搜索多维数组

时间:2014-08-01 10:30:16

标签: php arrays

我有一个看起来像

的数组
$arr = array(
     array('contents' => "any value",
           'tags' => '<th>'
     ),

     array('contents' => "any value",
           'tags' => "<th>"

     )
     .
     .
     .
);

我想回应索引&#34;内容&#34;

的价值

4 个答案:

答案 0 :(得分:1)

使用此(但您应该检查文档以提高您对阵列的了解):

$arr = array(
     array('contents' => "any value",
           'tags' => '<th>'
     ),

     array('contents' => "any value",
           'tags' => "<th>"

     )
);

foreach ($arr as $token){
    echo $token['contents'];
}

答案 1 :(得分:0)

试试这个

$arr = array(array('contents' => "any value", "tags" => "<th>"),array('contents' => "any value","tags" => "<th>"));

    foreach($arr as $arrays){
        echo $arrays["contents"];
    }

答案 2 :(得分:0)

array_walk对于这些事情非常有用。它遍历数组的每个元素并应用回调函数:

array_walk($arr, function($x) { if (isset($x['contents'])) echo $x['contents']; });

也许更简单,你可以自己循环遍历这些元素:

foreach ($arr as $a) { 
    if (isset($a['contents'])) echo $a['contents']; 
}

答案 3 :(得分:-2)

使用类似

的内容
echo $arr["contents"]

获取您想要的值...

http://php.net/manual/en/language.types.array.php