Given array item $array["first level"]["second LVL"]
, how can I get the key string second LVL
itself, not the key-value-pair value?
More Detailed Example
I have an array item variable $array["address"]["city"]
that I am passing to a function like so:
<?php
printKey( $array["address"]["city"] );
function printKey( $array_item ) {
return "Output: " . keyValue(array_item);
}
?>
How can I get the key value string city
itself from the array item $array["address"]["city"]
?
I've seen array_search(), array_keys(), and key(), but none seem to do the trick without a for loop at the least.
EDIT / Clarification:
The problem is, for example, sometimes my function is passed $array["address"]["name"]
and sometimes it passes $array["address"]["company"]
.
I need to be able to dynamically output Name:
or Name:
Example function:
$array["address"]["name"] = "Andre";
$array["address"]["company"] = "StackNot";
function printITEMkeyAndValue( $arrayITEM ) {
//It's not possible to do a for loop on just an item, right? It's just a string (?)
return $array_item_key . ": " . $array_item_value;
}
echo printITEMkeyAndValue( $array["address"]["name"] );
echo printITEMkeyAndValue( $array["address"]["company"] );
Desired output:
Name: Andre
Company: StackNot