0
[items] => Array
    (
        [0] => Array
            (
                [product_option_id] => 328
                [option_id] => 26
                [name] => Product Type
                [type] => checkbox
                [group_no] => 1
                [option_value] => Array
                    (
                        [0] => Array
                            (
                                [product_option_value_id] => 1473
                                [option_value_id] => 68
                                [option_boolean_value] => True
                                [option_cost] => 10.0000
                                [option_enable] => 1
                                [apply_default] => 1
                                [apply_option] => 0
                            )

                        [1] => Array
                            (
                                [product_option_value_id] => 1474
                                [option_value_id] => 151
                                [option_boolean_value] => False
                                [option_cost] => 0.0000
                                [option_enable] => 1
                                [apply_default] => 0
                                [apply_option] => 0
                            )

                    )

                [required] => 1
                [optionapply] => A
                [booleanvalue] => True
                [applyheading] => 1
                [flagheading] => 0
                [dhead_id] => 0
                [routes_dephead_id] => Array
                    (
                        [0] => 44
                        [1] => 37
                    )

                [routes_id] => Array
                    (
                        [0] => 948
                        [1] => 949
                    )

            )

我怎样才能得到 68 的关键option_value_id。这里 68 不是静态的,每次它都是动态的,我想要动态的解决方案。

4

2 回答 2

0
<?php
function recursive_array_search($needle,$haystack) {
    foreach($haystack as $key=>$value) {
        $current_key=$key;
        if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) {
            return $current_key;
        }
    }
    return false;
}

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

于 2013-09-27T06:59:29.890 回答
0

试试这个。

function search_id($array, $id) 
    foreach ($array['items'] as $key => $val) {
        foreach($val['option_value'] as $option_key => $option_value)
        {
             if ($option_value['option_value_id'] == $id) 
             {
                 return $option_key;
             }
        }
   }
于 2013-09-27T07:06:37.640 回答