views:

35

answers:

2

Good day everyone.

I have an regular array (this is the print_r result, the array can have from 1 to n positions):

Array
(
    [1] => value1
    [2] => value2
    [3] => value3
)

I have another array defined elsewhere as:

$array_def['value1']['value2']['value3'] = array(
 'fl' => 'field1',
 'f2' => 'field2',
);

Using the first array result, how can i check if $array_def exists? In other words, i need to use a flat array values to check if a multidimensional array correspondence exists; keep in mind that the values can repeat in the first array, therefore flipping values with keys it's not an option as it will collide and remove duplicated values.

Thanks in advance.

+1  A: 

You can do it this way:

$a = array(1=>'value1', 2=>'value2', 3=>'value3');
$array_def[$a[1]][$a[2]][$a[3]] = array(
 'fl' => 'field1',
 'f2' => 'field2',
);

I don't think there's any shortcut or special built-in function to do this.

Bill Karwin
This is assuming $a will always have 3 elements and $array_def too, i mean, this is a flat solution, not a dynamic one, thanks for the effort though =)
Kusanagi2k
A: 

Found the perfect function for you. returns not only exists, but position within a multi-dimensional array..

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

dated: 03-Nov-2004 11:13 too much to copy/paste

you can then loop over your flat array and foreach:

multi_array_search($search_value, $the_array)

FatherStorm
This seems to be kinda the opposite of what the OP was looking for.
cHao
Exactly, i need to search keys in array A using values from array B, this returns keys using a value, effort appreciated though
Kusanagi2k