jeudi 3 octobre 2019

How to check multidimensional arrays for the given key value pairs ie. exactly same keys and values?

when compared with the main array it should return the matching keys of the main array

For example:

$a = array(
   'a' => array('key1' => 'value1', 'key2' => 'value1', 'key3' => 'value1'),
   'b' => array('key1' => 'value2', 'key2' => 'value2', 'key3' => 'value2'), 
   'c' => array('key1' => 'value3', 'key2' => 'value3', 'key3' => 'value3'),
   'd' => array('key1' => 'value2', 'key2' => 'value2', 'key3' => 'value4')
);


1: $search1 = array('key1' => 'value2', 'key2' => 'value2');

when comparing with above array search1 it should return key 'b' and 'd'

ie. ['b','d']

    2: $search2 = array('key1' => 'value3', 'key3' => 'value3');

when comparing with above array search2 it should return key 'c'

ie. ['c']

    3: $search3 = array('key1' => 'value3', 'key2' => 'value3', 'key3' => 'value3' );

when comparing with above array search3 it should return key 'c'

ie. ['c']

    4: $search4 = array('key1' => 'value2');

when comparing with above array search4 it should return key 'b' and 'd'

ie. ['b','d']



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire