Array
(
[0] => Array
(
[name] => A
[id] => 1
[phone] => 416-23-55
[Base] => Array
(
[city] => toronto
)
[EBase] => Array
(
[city] => North York
)
[Qty] => 1
)
(
[1] => Array
(
[name] => A
[id] => 1
[phone] => 416-53-66
[Base] => Array
(
[city] => qing
)
[EBase] => Array
(
[city] => chong
)
[Qty] => 2
)
)
How can I get the all the key value with the format "0, name, id, phone, Base, city, Ebase, Qty"?
Thank you!
The array_keys() is a built-in function in PHP and is used to return either all the keys of and array or the subset of the keys. Parameters: The function takes three parameters out of which one is mandatory and other two are optional.
PHP array_key_exists() Function The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
To directly answer your question, no. PHP arrays can only contain one set of data for the key.
Try this
function array_keys_multi(array $array)
{
$keys = array();
foreach ($array as $key => $value) {
$keys[] = $key;
if (is_array($value)) {
$keys = array_merge($keys, array_keys_multi($value));
}
}
return $keys;
}
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