Had a hard time wording this in google so I figure ill ask here.
I have an array like such:
Array ( [a] => 'a' [b] => 'b' [c] => 'c' )
Is there an easy way to convert the keys to numerical values like such? Is there a built in function, or will I have to make one?
Array ( [0] => 'a' [1] => 'b' [2] => 'c' )
Thanks!
If you have a value and want to find the key, use array_search() like this: $arr = array ('first' => 'a', 'second' => 'b', ); $key = array_search ('a', $arr); $key will now contain the key for value 'a' (that is, 'first' ).
The array_flip() function is used to exchange the keys with their associated values in an array. The function returns an array in flip order, i.e. keys from array become values and values from array become keys. Note: The values of the array need to be valid keys, i.e. they need to be either integer or string.
The array_keys() function returns an array containing the keys.
The array_flip() function flips/exchanges all keys with their associated values in an array.
You want the array_values function.
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