Forum : I am not interested in the values in the arrays, how can I discard them?
Brief description  about Online courses   join in Online courses
View prabeen  patra 's Profile

I am not interested in the values in the arrays, how can I discard them?

I am not interested in the values in the arrays, how can I discard them???????
Asked by prabeen patra | Mar 17, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Prabeen,
One simple way to do this, if you just want the information about the keys, is to use the array_keys function to create an array of the keys. It does what it says on the tin, but here's a quick example:

<?php

$values = array(10=>"I","Don't","Care","About","Values");
print_r($values);

$whatvalues = array_keys($values);
print_r($whatvalues);
?>

Here is the resultant output from this:

Array
(
[10] => I
[11] => Don't
[12] => Care
[13] => About
[14] => Values
)
Array
(
[0] => 10
[1] => 11
[2] => 12
[3] => 13
[4] => 14
)

We can see that the values have been discarded and we now have an array containing the keys as the values.
Mar 17, 2010