Home PHP How to print the contents of an array using PHP?
 
 
 

How to print the contents of an array using PHP?

PDF Print E-mail

Question: How to print the contents of an array using PHP?

 

Answer: 

//Array example
$arr = array('one','two','three','four');

Use the print_r function.

Example: print_r($arr);

 

The example above will print out the following:
Array ( [0] => one [1] => two [2] => three [3] => four )

 

NOTE: If you want to have the contents of the array displayed in a more readable format, add a echo '<pre>'; statement before calling the print_r function.

Example of the results:

Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)


Explanation:

print_r - Prints human-readable information about a variable (PHP 4, PHP 5)

 

 

+/-
  • LJ - Very cool.
    Nice one man, thanks for this, yea i remember reading up on this in some pdf
    recently! :)
  • TechPortal - Cool
    I'm glad this was helpful. B)
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!