duk*_*vin 1 php multidimensional-array
我有一个数组美食像:
Array
(
[apple] => Array
(
[color] => red
[type] => fruit
)
[choco] => Array
(
[color] => brown
[type] => candy
)
)
Run Code Online (Sandbox Code Playgroud)
有功能我可以做:
get_key($ food,0)它将返回索引0,apple
get_key($ food,1)返回choco
你可以这样做 :
$keys = array_keys($array);
echo $keys[0];
echo $keys[1];
Run Code Online (Sandbox Code Playgroud)
function get_key($array, $index) {
$allItems = array_keys($array);
$selectedItem = $allItems[$index];
return $selectedItem;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
672 次 |
| 最近记录: |