Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Convert Array Keys

Tags:

arrays

php

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!

like image 777
grep Avatar asked Jun 22 '11 21:06

grep


People also ask

How get key from value in array in PHP?

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' ).

How do I flip an array in PHP?

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.

What is array_keys () used for in PHP?

The array_keys() function returns an array containing the keys.

What is the use of array_flip () function?

The array_flip() function flips/exchanges all keys with their associated values in an array.


1 Answers

You want the array_values function.

like image 85
borrible Avatar answered Sep 16 '22 11:09

borrible