-1

リピーターを含むフォームによって作成された大きな配列があるため、配列は無限に大きくなる可能性があります。する必要がある:

  • 1.配列を検索する
  • 2. [field_18] のすべての値を取得する
  • 3. すべての値 ('-5'、'-1'、ect ) を含む配列を出力します。
Array
(
[field_22] => Mid-Distance Free
[field_25] => Array
    (
        [0] => 1
    )

[field_23] => Its a freestyle workout
[field_6] => Array
    (
        [0] => Array
            (
                [field_7] => 1
                [field_8] => 0
                [field_9] => 0
                [field_10] => Array
                    (
                        [0] => Array
                            (
                                [field_11] => 6
                                [field_12] => 50
                                [field_13] => jumping jacks
                                [field_14] => 
                            )

                        [1] => Array
                            (
                                [field_11] => 2
                                [field_12] => 20
                                [field_13] => pushups
                                [field_14] => 
                            )

                        [acfcloneindex] => Array
                            (
                                [field_11] => 1
                                [field_12] => 1
                                [field_13] => pushups
                                [field_14] => 
                            )

                    )

            )

        [acfcloneindex] => Array
            (
                [field_7] => 1
                [field_8] => 0
                [field_9] => 0
                [field_10] => Array
                    (
                        [acfcloneindex] => Array
                            (
                                [field_11] => 1
                                [field_12] => 1
                                [field_13] => pushups
                                [field_14] => 
                            )

                    )

            )

    )

[field_17] => Array
    (
        [0] => Array
            (
                [field_7] => 1
                [field_8] => 0
                [field_9] => 0
                [field_10] => Array
                    (
                        [0] => Array
                            (
                                [field_11] => 5
                                [field_12] => 100
                                [field_13] => Freestyle
                                [field_14] => Descend 1-5
                                [field_18] => 5
                            )

                        [1] => Array
                            (
                                [field_11] => 10
                                [field_12] => 50
                                [field_13] => Drill
                                [field_14] => Choice
                                [field_18] => 5
                            )

                        [2] => Array
                            (
                                [field_11] => 1
                                [field_12] => 400
                                [field_13] => Freestyle
                                [field_14] => Negative Split
                                [field_18] => -20
                            )

                        [acfcloneindex] => Array
                            (
                                [field_11] => 1
                                [field_12] => 25
                                [field_13] => Butterfly
                                [field_14] => 
                                [field_18] => 
                            )

                    )

            )

        [acfcloneindex] => Array
            (
                [field_7] => 1
                [field_8] => 0
                [field_9] => 0
                [field_10] => Array
                    (
                        [acfcloneindex] => Array
                            (
                                [field_11] => 1
                                [field_12] => 25
                                [field_13] => Butterfly
                                [field_14] => 
                                [field_18] => 
                            )

                    )

            )

    )

[field_19] => Array
    (
        [0] => Array
            (
                [field_7] => 1
                [field_8] => 0
                [field_9] => 1
                [field_10] => Array
                    (
                        [0] => Array
                            (
                                [field_11] => 20
                                [field_12] => 100
                                [field_13] => Freestyle
                                [field_14] => Hold 500 race pace
                                [field_18] => -5
                            )

                        [1361771245813] => Array
                            (
                                [field_11] => 1
                                [field_12] => 75
                                [field_13] => Butterfly
                                [field_14] => 
                                [field_18] => 
                            )

                        [acfcloneindex] => Array
                            (
                                [field_11] => 1
                                [field_12] => 125
                                [field_13] => Butterfly
                                [field_14] => 
                                [field_18] => 
                            )

                    )

            )

        [acfcloneindex] => Array
            (
                [field_7] => 
                [field_8] => 0
                [field_9] => 0
                [field_10] => Array
                    (
                        [acfcloneindex] => Array
                            (
                                [field_11] => 1
                                [field_12] => 25
                                [field_13] => Butterfly
                                [field_14] => 
                                [field_18] => 
                            )

                    )

            )

    )

[field_21] => Array
    (
        [acfcloneindex] => Array
            (
                [field_7] => 
                [field_8] => 0
                [field_9] => 0
                [field_10] => Array
                    (
                        [acfcloneindex] => Array
                            (
                                [field_11] => 
                                [field_12] => 25
                                [field_13] => Butterfly
                                [field_14] => 
                                [field_18] => 
                            )

                    )

            )

    )

)

すべてのキーを調べようとしましたが、そこからどこに行くべきかわかりませんでした。これは私が使用していたコードです。

function array_keys_multi(array $array)
{
$keys = array();

foreach ($array as $key => $value) {
    $keys[] = $key;

    if (is_array($array[$key])) {
        $keys = array_merge($keys, array_keys_multi($array[$key]));
    }
}

return $keys;
}
4

3 に答える 3

0

array_walk_recursiveを使用できます

$array = array(/*some data*/);
$result = array();
$search_key = 'field_18';
array_walk_recursive($array, function($item, $key)use($search_key, &$result){
if ($search_key == $key)
  $result[]=$item;
});
$search_values = array('-5', '-1');
$result2 = array();
array_walk_recursive($array, function($item, $key)use($search_values, &$result2){
if (is_array($item) && array_intersect($item, $search_values))
  $result2[]=$item;
});

PSコードはテストされていません。単なるアイデアです。

于 2013-02-25T06:02:26.257 に答える
0

これを試して :

function array_key_exists_r($needle, $haystack)
{
    //$result  = array();
    global $result;
    if(is_array($haystack)){
        foreach ($haystack as $key=>$v) {
            if (is_array($v)) {
                array_key_exists_r($needle, $v);
            }
            else{
                if($key == $needle){
                   $result[] = $v;
                }
            }
        }
    }

    return $result;
}


echo "<pre>";
print_r(array_key_exists_r("field_18", $your_array));
于 2013-02-25T06:13:54.820 に答える
0

array_walk を使用すると主張するように、配列が非常に大きくなる可能性があるため、危険な場合があります。PHP 5.5 を使用している場合は、単純な foreach ループを作成して、それぞれの値を生成できます。そうすれば、消費関数は必要な数のエントリを取得できます。

于 2013-02-25T06:14:24.443 に答える