PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How can I easily view all members of an array?


To view all the members of an array with minimal code, the simplest way is to use print_r - this will show you the members of an array like this:

<?php
$values 
= array("banana","apple","pear","banana");
print_r($values);
?>


Outputs:

Array
(
[0] => banana
[1] => apple
[2] => pear
[3] => banana
)

Less well known but useful when you require more detailed information on each array member is the function var_dump.

This will return the below for the array members above:

array(4) {
[0]=>
string(6) "banana"
[1]=>
string(5) "apple"
[2]=>
string(4) "pear"
[3]=>
string(6) "banana"
}



More arrays PHP Questions

How do I turn an array into a string?
How do I find the size of an array?
How do I return all the values in an array?
How can I create an array of the letters of the alphabet?
How can I loop through the members of an array?