views:

580

answers:

3

If I have an array as $keys => $values, how can I get two arrays of $keys and $values?

+23  A: 

Using array_keys() and array_values().

$keys = array_keys($array);
$values = array_values($array);
chaos
+13  A: 

array_keys and array_values will return a numerical array of the keys/values of a given array:

$keys = array_keys($array);
$values = array_values($array);

Or if you want a foreach solution:

$keys = array();
$values = array();
foreach ($array as $key => $value) {
    $keys[] = $key;
    $values[] = $value;
}
Gumbo
+1 for multiple ways.
nilamo
+11  A: 
$keys = array_keys($thearray);
$values = array_values($thearray);
Silfverstrom