Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
PHP vfprintf() Function
Next article icon

PHP | print_r() Function

Last Updated : 26 Apr, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report

The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable.

Syntax:

print_r( $variable, $isStore )

Parameters: This function accepts two parameters as shown in above syntax and described below.

  1. $variable: This parameter specifies the variable to be printed and is a mandatory parameter.
  2. $isStore: This an option parameter. This parameter is of boolean type whose default value is FALSE and is used to store the output of the print_r() function in a variable rather than printing it. If this parameter is set to TRUE then the print_r() function will return the output which it is supposed to print.

Return Value: If the $variable is an integer or a float or a string the function prints the value of the variable. If the variable is an array the function prints the array in a format which displays the keys as well as values, a similar notation is used for objects. If the parameter $isStore is set to TRUE then the print_r() function will return a string containing the information which it is supposed to print.

Below programs illustrate the print_r() function:

Program 1:




<?php
  
// PHP program to illustrate
// the print_r() function
  
// string variable
$var1 = "Welcome to GeeksforGeeks";
  
// integer variable
$var2 = 101;
  
// array variable
$arr = array('0' => "Welcome", '1' => "to", '2' => "GeeksforGeeks");
  
// printing the variables
print_r($var1);
echo"\n";
print_r($var2);
echo"\n";
print_r($arr);
  
?>
 
 

Output:

  Welcome to GeeksforGeeks  101  Array  (      [0] => Welcome      [1] => to      [2] => GeeksforGeeks  )  

Program 2:




<?php
  
// PHP program to illustrate the print_r()
// function when $isStore is set to true
  
// array variable
$arr = array('0' => "Welcome", '1' => "to",
                     '2' => "GeeksforGeeks");
                       
// storing output of print_r() function
// in another variable
$results = print_r($arr, true); 
  
echo $results;
  
?>
 
 

Output:

  Array  (      [0] => Welcome      [1] => to      [2] => GeeksforGeeks  )  

Reference:
http://php.net/manual/en/function.print-r.php



Next Article
PHP vfprintf() Function

S

sid4321
Improve
Article Tags :
  • PHP
  • Web Technologies
  • PHP-input-output

Similar Reads

  • PHP vprintf() function
    The vprintf() function in PHP is an inbuilt function which is used to display array values as a formatted string Display array values as a formatted string according to format it is work similar as printf() but accepts an array of arguments, in place of variables number of arguments. Returns the len
    5 min read
  • PHP sprintf() Function
    The sprintf() function is an inbuilt function in PHP that is used for formatting strings in a manner similar to the C language's printf() function. It allows you to create formatted strings by substituting placeholders with corresponding values. Syntax: string sprintf(string $format, mixed ...$value
    2 min read
  • PHP vsprintf() Function
    The vsprintf() function in PHP is an inbuilt function and used to display array values as a formatted string. The array elements will be inserted at the percent (%) signs in the main string. Display array values as a formatted string according to its format and accepts an array argument in place of
    5 min read
  • PHP vfprintf() Function
    The vfprintf() function is an inbuilt function in PHP that is used to write formatted information to a stream, such as a file or the output screen. Syntax: vfprintf(resource $stream, string $format, array $values): Parameters: This function accepts three parameters that are described below. $stream:
    2 min read
  • PHP stristr() Function
    The stristr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-insensitive. Syntax : strist
    2 min read
  • PHP rtrim() Function
    The rtrim() function is a built-in function in PHP which removes whitespaces or other characters (if specified) from the right side of a string. Syntax: rtrim( $string, $charlist )Parameters: The function rtrim() accepts two parameters as shown in the above syntax. Out of these two parameters, one i
    2 min read
  • PHP strtr() Function
    The strtr() is an inbuilt function in PHP which is used to replace a substring in a string to a given string of characters. It also has the option to change a particular word to a different word in a string. The function is case sensitive. Syntax: strtr($string, $string1, $string2) or, strtr($string
    4 min read
  • PHP | ctype_print() Function
    The ctype_print() Function in PHP used to check each and every character of a string are visible or not. If all characters of string are visible then returns TRUE , else if there are any control character then return FALSE. Control Character: A character that does not represent a printable character
    2 min read
  • PHP strstr() Function
    The strstr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-sensitive. Syntax : strstr( $
    2 min read
  • PHP | rewind( ) Function
    The rewind() function in PHP is an inbuilt function which is used to set the position of the file pointer to the beginning of the file. Any data written to a file will always be appended if the file is opened in append ("a" or "a+") mode regardless of the file pointer position. The file on which the
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences