How can I make two numeric arrays (one for keys one for values - the opposite of array combine)
Source info:
John => Physics, Mary => Medicine, Gary => Drama,
Output to
0=>Physics, 1=>Medicine, 2=>Drama
and
0=>John, 1=>Mary, 2=>Drama
It seems easy, but I've had no luck.
Call array_keys()
and array_values()
on your associative array respectively.
If for whatever reason you must have numeric indices that start at 1 (as in your original question before any edits), you'll need to do a little more:
$keys = array_keys($array);
array_unshift($keys, NULL);
unset($keys[0]);
$values = array_values($array);
array_unshift($values, NULL);
unset($values[0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With