How to access nested associative array data in PHP(如何在 PHP 中访问嵌套关联数组数据)
本文介绍了如何在 PHP 中访问嵌套关联数组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个索引数组,其中包含一个嵌套关联数组和一个嵌套索引数组:
I have an indexed array that contains a nested associative array AND a nested indexed array:
$myArray = array (
0 => array (
'name' => 'Paul',
'age' => '23',
'hobbies' => array (
0 => 'basketball',
),
'pets' => 'dog',
),
);
如何访问所有这些值并将它们转换为变量?
How can I access all of these values and convert them into variables?
推荐答案
你可以直接从 Array 访问
You can just access from Array
像这样写你的数组
$myArray = [
0 => [
'name' => 'Paul',
'age' => '23',
'hobbies' => [
0 => 'basketball',
],
'pets' => 'dog'
]
];
假设你想访问第一个元素的名字
Suppose you want to access name of first elements
echo $myArray[0]['name']; // it will print 'Paul'
echo $myArray[0]['hobbies'][0]; // it will print basketball
现在你可以像上面一样获取.
Now you can fetch like above.
这篇关于如何在 PHP 中访问嵌套关联数组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在 PHP 中访问嵌套关联数组数据


猜你喜欢
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Laravel 仓库 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01