I have an array that looks like
$numbers = array('first', 'second', 'third');
I want to have a function that will take this array as input and return an array that would look like:
array( 'first' => 'first', 'second' => 'second', 'third' => 'third' )
I wonder if it is possible to use array_walk_recursive
or something similar...
Here array() function is used to create associative array.
For example, the following statement defines an associative array a with key signature [ int, string ] and stores the integer value 456 in a location named by the tuple [ 123, "hello" ]: a[123, "hello"] = 456; The type of each object contained in the array is also fixed for all elements in a given array.
keyN => valueN, ]; Note: The comma after the last Key-Value pair is optional. The Key can be of either integer or string type.
You can use the array_combine
function, like so:
$numbers = array('first', 'second', 'third'); $result = array_combine($numbers, $numbers);
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