I have the following array ($arrayres) (example data)
Array
(
[0] => Array
(
[description] => somedata
[amount] => 52,6
[b_id] => Array
(
[0] => 138950106
[1] => 138950106
)
)
[1] => Array
(
[description] => somedata
[amount] => 4,9
[b_id] => Array
(
[0] => 138911857
[1] => 138911857
)
)
)
Then I have a query that returns the b_id in its results as well. I need to find which of the b_id’s are included in the array and their respective position in the array. So I perform an array_rearch
while ($dbres = $res->fetchRow(MDB2_FETCHMODE_ASSOC))
{
$key = array_search($dbres['b_id'], $arrayres);
if ($key)
{
$keys[] = $key;
}
}
But there seems to be no match. print_r($keys) is always empty, although there are results that contain the b_id’s in question.
What am I doing wrong?
When you do
array_search($dbres['b_id'], $arrayres);you’re searching for keys onto “the first layer” of that nested array and, of course, theare are only0or1as keysYou could do something like that
and that has to be inserted into the while loop