I have this dynamic array, generate after a submit $_POST.
Array
(
[0] => Array
(
[0] => lng_criteria_balance
[1] => Array
(
[0] => lng_type_balance_positive
)
)
[1] => Array
(
[0] => lng_criteria_sex
[1] => Array
(
[0] => F
)
)
[2] => Array
(
[0] => lng_criteria_note
[1] => Array
(
[0] => cane
)
)
)
Array is variable, and it's key also. I need to search if a specified value exists. I did try this but
<?php
if (in_array('lng_criteria_balance', $args))
{
echo 'found!';
}
else
{
echo 'not found :(';
}
But it prints "not found". Thank you.
PS I could check with a foreach loop, but I would not use it (for best performance)
in_arraysearches in just one array not a multidimensional array.Array ( [lng_criteria_balance] => lng_type_balance_positive, [lng_criteria_sex] => F, [lng_criteria_note] => cane, ). It also simplifies your code that uses it and makes possible the usage of the PHP standard functionsin_array(),array_key_exists(),array_search(),isset()a.s.o.