我想解析数组并希望从数组中获取sid
值。我已经使用foreach进行了跟踪,如下所示。我在Drupal模块的第二个foreach循环中发现了一条警告消息。如何添加
foreach($submission as $sub) {
foreach($sub as $a) { // Warning: Invalid argument supplied for foreach()
if (isset($a[1])) {
$sid = $a[1]->sid;
}
}
}
$submission
值:
Array
(
[build_info] =>
Array
(
[args] => Array
(
[0] => stdClass Object
(
)
[1] => stdClass Object
(
[sid] => 176
[nid] => 2
[submitted] => 1522130239
[remote_addr] => ::1
[uid] => 1
[name] => admin
[is_draft] => 0
)
)
)
)
答案 0 :(得分:2)
根据我从你的片段中理解的内容,它应该是以下内容:
$sid = $submission['build_info']['args'][1]->sid;
或者如果你喜欢它在foreach循环中:
foreach ($submission['build_info']['args'] as $key => $args) {
$sid = isset($args->sid) ? $args->sid : NULL;
}