Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数组数组中获取正确的变量_Php_Arrays_Foreach - Fatal编程技术网

Php 从数组数组中获取正确的变量

Php 从数组数组中获取正确的变量,php,arrays,foreach,Php,Arrays,Foreach,我正试图弄清楚数据将如何形成,以及如何从中获得我想要的值: $items[$qid] = _content_sync_server_prepare($entity, $entity_type); \u content\u sync\u server\u prepare()将返回此-返回数组('entity\u type'=>$entity\u type,'entity'=>$entity) $qid是一个表示数字的变量 我想为每个$qid值获取$entity_type值 我相信我会使用fore

我正试图弄清楚数据将如何形成,以及如何从中获得我想要的值:

$items[$qid] = _content_sync_server_prepare($entity, $entity_type);
\u content\u sync\u server\u prepare()
将返回此-
返回数组('entity\u type'=>$entity\u type,'entity'=>$entity)

$qid是一个表示数字的变量

我想为每个$qid值获取$entity_type值

我相信我会使用foreach循环:

foreach ($items as $item => $value) {
$entity_type_value = $item[$value];
}

我说得对吗?还是有更好的方法?

我认为这是正确的方法:

foreach($items as $key => $value) {
    $entity_type_value = $value['entity_type'];
}

因为$item是字符串而不是数组,所以foreach语句将不起作用

以下各项应有效(未经测试):

foreach ($items as $item) {
    $entity_type_value = $item['entity_type'];
}