php - 如何“从 PHP 中的嵌套数组结构中获取数据”
问题描述
我正在尝试从数组中获取数据,包括DetectedText
值和BoundingBox
所有四个值。但面临问题。
完整的数据在“$prepared_arr”中,给定数组的结构如下所示。
print_r ($prepared_arr);// variable having complete data
Array //output of above array used in pipeline
(
[0] => Array
(
[DetectedText] => The number of goals
[BoundingBox] => Array
(
[Width] => 0.66954100131989
[Top] => 0.04796177148819
[Left] => 0.2710283100605
[Height] => 0.072451308369637
)
)
[1] => Array
(
[DetectedText] => in world cup match
[BoundingBox] => Array
(
[Width] => 0.33683118224144
[Top] => 0.12350185215473
[Left] => 0.12564577162266
[Height] => 0.066131837666035
)
)
)
如果我使用 print_r ($prepared_arr[1]) 它只返回索引 1 的完整数据。先感谢您
解决方案
您可以使用foreach
从数组中获取数据,例如:
// with your example
foreach($prepared_arr as $val)
{
echo "DetectedText: ". $val['DetectedText']."<br/>"; // using br for line break
foreach ($val['BoundingBox'] as $key => $valueInner) {
echo $key.": ".$valueInner."<br/>"; // using br for line break
}
}
推荐阅读
- unit-testing - 使用 b 按钮“to”对 vue 路由进行单元测试
- r - 如何重复对数据进行子集化并跨 R 中的列执行函数?
- amazon-web-services - 连接到私有 VPC 的 AWS Lambda 无法启动/停止 EC2 实例
- java - Spring boot 允许用户同时登录超过一次(已解决)但它无法重定向到特定网页(仍然无法正常工作)
- haskell - 变量不在范围内:x :: Picture (Haskell)
- javascript - MVC 中的 ajax 调用导致“主线程上的 xmlhttprequest 已弃用”警告
- ios - SwiftUI ForEach 视图第一次没有更新
- r - 使用操作按钮的闪亮渲染图
- sql-server - 触发器未按预期工作以计算累积运行时间
- python - 如何将字典列表中的值与输入值进行比较