Поиск в многомерном массиве

Вот многомерный массив:

[0] => Array (   
    [order_total_id] => 8160  
    [order_id] => 2048 [code] => sub_total  
    [title] => Medzi-súčet  
    [text] => 5,75€  
    [value] => 5.7500  
    [sort_order] => 1 )   
[1] => Array (   
    [order_total_id] => 8161  
    [order_id] => 2048  
    [code] => shipping  
    [title] => Doporučený list  
    [text] => 2,00€  
    [value] => 2.0000  
    [sort_order] => 3 )  
[2] => Array (  
    [order_total_id] => 8162  
    [order_id] => 2048  
    [code] => tax  
    [title] => DPH 20%  
    [text] => 1,15€  
    [value] => 1.1500  
    [sort_order] => 5 )  
[3] => Array (  
    [order_total_id] => 8163  
    [order_id] => 2048  
    [code] => total  
    [title] => Celkom  
    [text] => 8,90€  
    [value] => 8.9000  
    [sort_order] => 6 )  

Мой вопрос: можно ли получить [value] => 8.9000 ([value] может быть несколько раз в массиве m.d.)? Я думаю, что правильный способ сделать это - сначала найти [code] => total для определения правильного массива, а затем найти ключ [total] в том же массиве. Почему? Поскольку [code] => total может находиться в подмассивах [0], [1], [2], [3], иногда существует только подмассив [0], [1].

Если бы это сработало, было бы неплохо найти [code] => shipping и [value] => 2.0000

Спасибо вам, ребята.


person Adrian    schedule 22.03.2013    source источник


Ответы (1)


http://www.php.net/manual/en/function.array-search.php#69965

<?php    

function myMulti_Array_Search($theNeedle, $theHaystack, $keyToSearch) 
        { 
        foreach($theHaystack as $theKey => $theValue) 
            { 
            $intCurrentKey = $theKey;    

            if($theValue[$keyToSearch] == $theNeedle) 
                { 

                return $intCurrentKey ; 
                } 
            else 
                { 
                return 0; 
                } 
            } 
        } 

?>
person Interwebtual    schedule 22.03.2013