从cake php多维数组中获取价值

时间:2014-12-15 05:37:19

标签: php arrays cakephp multidimensional-array

我尝试过很多东西,但无法获得输出,真的很感激任何帮助 谢谢

Array ( 

[0] => Array ( [Toolrepos] => 
            Array ( 
                [id] => 28 
                [created] => 2014-12-13 
                [tool_type] => new1 
                [tool_partnum] => new3 
                [tool_vernum] => 57.0.5 
                [box_id] => 28 
                [request_date] => 2014-12-14 
                [delivered_date] => 2014-12-14 ) ) 

[1] => Array ( [Toolrepos] => 
            Array ( 
                [id] => 29 
                [created] => 2014-12-13 
                [tool_type] => new4 
                [tool_partnum] => new5 
                [tool_vernum] => 1.2.56 
                [box_id] => 28 
                [request_date] => 2014-12-14 
                [delivered_date] => 2014-12-14 ) ) 

[2] => Array ( [Toolrepos] => 
            Array ( [id] => 29 
                [created] => 2014-12-13 
                [tool_type] => SeatApp 
                [tool_partnum] => sw2 
                [tool_vernum] => 1.1.2 
                [box_id] => 34 
                [request_date] => 2014-12-13 
                [delivered_date] => 2014-12-13 ) ) )

我需要输出如下

if box_id = '28' then i need their corresponding values for 'created','tool_type','tool_vernum'. Sometimes I need only 'created' value for matching box_id. Thank you

1 个答案:

答案 0 :(得分:0)

$box28s = array();
$i=0;
if (! empty($arr)) {
    foreach ($arr as $elem) {
        $curr = ! empty($elem['Toolrepos']) ? $elem['Toolrepos'] : NULL;
        if (! empty($curr)) {
            foreach ($curr as $k => $v) {
                if ($k == 'id' && $v == 28) {
                    $box28s[$i] = $curr;
                }
            }
        }
        ++$i;
    }
}