Forum : How do I return all the values in an array?
Brief description  about Online courses   join in Online courses
View Balu  Prasad 's Profile

How do I return all the values in an array?

How do I return all the values in an array??????
Asked by Balu Prasad | Mar 17, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Balu,
Sometimes the relationship between the key and the value in an array will be of importance to us, but often that is not the case and all we really want to concentrate on are the values in the array.
For times like this, PHP provides us with the array_values function, which will simply return is an array containing the values, like so:

<?php
$example = array(572=>"i","don't","care","much","for","keys");
print_r($example);
$values = array_values($example);
print_r($values);
?>
Which prints:
Array
(
[572] => i
[573] => don't
[574] => care
[575] => much
[576] => for
[577] => keys
)
Array
(
[0] => i
[1] => don't
[2] => care
[3] => much
[4] => for
[5] => keys
)
You can see that the keys from the initial array are gone, but if we weren't interested in those then that's just fine!
Mar 17, 2010