PHP print_r() Function With Example — Phpflow.com

This PHP tutorial helps you to learn basic print_r statement with examples. The print_r() PHP function is used to return an array in a human readable form.

The print_r() displays information about a variable in a way that’s readable by humans.

pre tag

We’ll use pre tag to display print_r() method returned value. The 'pre' tag denotes that the code has been preformatted. The text will be shown in a fixed-width font with this tag. It maintains line breaks and spaces, making it easier to read for humans.

Syntax :

  • var_name : The variable being printed.
  • return_output : It helps to capture the output in a variable, the parameter should set TRUE. The default value is FALSE.

Return Value: print_r(var_name, return_output)

If the variable is an integer or a float or a string the function returns the value of the variable.
If the variable is an array the function returns keys and elements, a similar notation is used for the object. Setting TRUE to return_output parameter the function returns a string.

Output :

Sample Example PHP print_r()

The print_r(), var_dump() and var_export() will also show protected and private properties of objects. Static class members will not be shown.
The difference of the var_dump() and var_export() is that var_export returns valid PHP code, whereas var_dump does not.

Originally published at https://www.phpflow.com on April 23, 2022.

--

--

--

Hey, I am Parvez Alam. A software developer since 2009. I am a programming addict. I love learning and sharing knowledge. https://www.phpflow.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

【Airdrop】NFT Giveaway-COCOS Thanksgiving celebration

What if you could make git commit in past with time travel?

Demystifying Let’s Encrypt

Fetching records using fetchone() and fetchmany()

How to create a simple event streaming in Laravel?

Why Haskell?

Centralized Logging — EFFK — Elastic Search + Fluent Bit + Fluentd + Kibana

{UPDATE} First Words for Kids and Toddlers Professional: Preschool learning reading through letter…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parvez Alam

Parvez Alam

Hey, I am Parvez Alam. A software developer since 2009. I am a programming addict. I love learning and sharing knowledge. https://www.phpflow.com/

More from Medium

Running Laravel Out Of A Subdirectory

New features were added in Laravel 8.74.0

Laravel Eloquent relationships have a bunch of “with” methods you might not know about.

How To Convert PHP String to Array — Phpflow.com