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

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!



ASK A QUESTION

More arrays PHP Questions

hi, i am querying the DB as follows: $result=mysql_query("SELECT name,items FROM mytable WHERE user_id='$id'"); now,i want to create an array to insert the values that are as a result of this query e'g let's say this is the resultant data: n

How do I remove an element from an array without changing the index values for the rest of the array?

OK I've been trying to echo out the arrays "$people and $other people" using the for-each method in alphabetical order. but when i see what this displays it does it in some other order. THIS IS THE CODE PHP Ch8 Lab

How do I generate an associative array like Jan => 10, Feb =>20 etc from a mysql table of 2 columns, month and val ?

HOW CAN I DELETE ALL THE ELEMENT OF THE ARRAY



Custom Search