Starting off I have two PHP arrays.
The first array has a length of dates in Y-m
order that has each of the 12 months in it with the years. This array looks like this...
Array
(
[0] => Array ( [ORDER] => Array ( [DATE] => 2008-10 [QTY] => 0 ) )
[1] => Array ( [ORDER] => Array ( [DATE] => 2008-11 [QTY] => 0 ) )
)
The second array has values that have been returned from a query and put into the array and are also in Y-m
order for may or may not have each month in it. The second one is like this.
Array
(
[0] => Array ( [ORDER] => Array ( [DATE] => 2008-11 [QTY] => 285 ) )
[1] => Array ( [ORDER] => Array ( [DATE] => 2008-12 [QTY] => 900 ) )
)
My end goal is to produce an array of the Y-m dates to use for a google line chart that will show a 0 if in that month no orders where placed. So that array should look like this..
Array
(
[0] => Array ( [ORDER] => Array ( [DATE] => 2008-10 [QTY] => 0 ) )
[1] => Array ( [ORDER] => Array ( [DATE] => 2008-11 [QTY] => 285 ) )
[2] => Array ( [ORDER] => Array ( [DATE] => 2008-12 [QTY] => 900 ) )
)
So the array item...
[1] => Array ( [ORDER] => Array ( [DATE] => 2008-11 [QTY] => 0 ) )
was removed as there was an entry in the second array that had a value with the same date.
Now I'm not sure if I'm going about this the right way but here's what I have so far.
foreach($FIRST_ARRAY as $key => $each)
{
foreach($each as $line)
{
$findMe = $line['DATE'];
if(in_array($findMe, $SECOND_ARRAY, true))
{
echo 'FOUND:'.$findMe;
}else{
echo $line['DATE'].' ';
echo $line['QTY'].' ';
echo '('.$findMe.')<br>';
}
}
}
All this is doing is printing out the First Array. It's not 'Matching' up the dates. Here's what its printing out...
2008-10 0 (2008-10) 2008-11 0 (2008-11) 2008-12 0 (2008-12)
Here's what I want it to print out...
2008-10 0 (2008-10) 2008-11 285 (2008-11) 2008-12 900 (2008-12)
The Question would be: Am I going about this all wrong or is there a better way of doing this.
I hope this all makes sense.
yyyy-mm
in ascending order? – Passerby Oct 12 '12 at 15:29