If I have an array as $keys => $values
, how can I get two arrays of $keys
and $values
?
views:
580answers:
3
+23
A:
Using array_keys()
and array_values()
.
$keys = array_keys($array);
$values = array_values($array);
chaos
2009-07-09 11:10:28
+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
2009-07-09 11:11:00
+1 for multiple ways.
nilamo
2009-07-18 18:50:15
+11
A:
$keys = array_keys($thearray);
$values = array_values($thearray);
Silfverstrom
2009-07-09 11:11:00