PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I return all the values in an array?


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!



Comment on this Question and Answer >>>

ASK A QUESTION

More arrays PHP Questions

Hi. i have a music samples website. in one table, id like a different sample to appear every time the page is refreshed. how do i acheve this? how can i alterate and retrieve these bloody mp3's? surely i can use a PHP script? thankyou

How do I sort an array by key?

How can I create an array of numbers easily?

How do I check if a variable is of array type?

i need to store a multi-dimensioned array into a file. there is plenty of info. on creating md-arrays but i cant find anything on writing a md-array to a file.



Custom Search