considering this array :
$segments = array(
"key1" =>"111",
"key2" =>"222",
"key3" =>"333",
"key4" =>"444"
);
I want to have these:
$key1
has the value of "111";
$key2
has the value of "222";
$key3
has the value of "333";
$key4
has the value of "444";
What can I do ?
The array_keys() function is used to get all the keys or a subset of the keys of an array. Note: If the optional search_key_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the array are returned.
The extract() function imports variables into the local symbol table from an array. This function uses array keys as variable names and values as variable values. For each element it will create a variable in the current symbol table. This function returns the number of variables extracted on success.
No. Arrays can only have integers and strings as keys.
This is not possible - array keys must be strings or integers.
PHP has a built-in function that does exactly this:
extract($segments);
http://php.net/manual/en/function.extract.php
use
extract($segments)
References:
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