How can I easily view all members of an array?
<?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"
}
Comment on this Question and Answer >>>
ASK A QUESTION
More arrays PHP Questions
How can I check if a value is already in an array?I am not interested in the values in the arrays, how can I discard them?
How do I find if a value is already in an array or not?
How do I sort an array by key?
How can I reset an array in PHP?
