[英]PHP: Get single value from complex array
I have the following: 我有以下内容:
Array ( [0] => Array ( [0] => Array ( [value] => 150109 [format] => [safe_value] => 150109 ) ) )
I need to get the value "150109", but how on earth do I accomplish that? 我需要获取值“ 150109”,但是到底该如何实现呢?
Top level: 顶层:
print_r($data);
// Output: Array ( [0] => Array ( [0] => Array ( [value] => 150109 [format] => [safe_value] => 150109 ) ) )
Outmost element: 最外层元素:
print_r($data[0]);
// Output: Array ( [0] => Array ( [value] => 150109 [format] => [safe_value] => 150109 ) )
Next level: 下一级:
print_r($data[0][0]);
// Output: Array ( [value] => 150109 [format] => [safe_value] => 150109 )
The final value 最终值
echo $data[0][0]['value'];
// Output: 150109
Accessing each layer of values this way makes it easier to figure out how to get to your desired value. 通过这种方式访问值的每一层,可以更轻松地弄清楚如何获得所需的值。 After a while this becomes more obvious.
一段时间后,这一点变得更加明显。
您可以在多维数组上连续使用数组的获取值:
$value = $array[0][0]["value"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.