-4

我有数组:

        $array = array(
            3 => array(
                'first' => 'aaa',
                'second' => '111',
                'third' => '!!!'
            ),
            7 => array(
                'first' => 'bbb',
                'second' => '222',
                'third' => '###'
            ),
            9 => array(
                'first' => 'ccc',
                'second' => '333',
                'third' => '^^^'
            ),

        );

和三个变量:

$first = 'bbb';
$second = '222';
$third = '###';

或者可以是数组:

$data = array(
     'first' => 'bbb',
     'second' => '222',
     'third' => '###'
);

我想从 $array 获取这些值的键。在这个例子中应该返回 7。

如何将此数组与 $first、$second 和 $third 或数组 $data 进行比较,并从 $array 中获取具有这些值的键?

4

1 回答 1

-1

尝试这个:

      $array = array(
        3 => array(
            'first' => 'aaa',
            'second' => '111',
            'third' => '!!!'
        ),
        7 => array(
            'first' => 'bbb',
            'second' => '222',
            'third' => '###'
        ),
        9 => array(
            'first' => 'ccc',
            'second' => '333',
            'third' => '^^^'
        ),
    );

    $data = array(
        'first' => 'bbb',
        'second' => '222',
        'third' => '###'
    );

    foreach ($array as $key => $val1) {
        $arr_diff = array_diff($val1, $data);

        if(empty($arr_diff))
        {
            echo $key;
        }
    }

foreach 循环会让你正确答案。

于 2013-10-11T11:39:08.373 回答