Ok, so I've got two arrays planned - which will be sorted based on a date or timestamp, as so:
array([date] => "8/12/12", [rating] => 300)
and lets say a second array looks like this:
array([date] => "8/12/12", [rating2] => 600)
I want to combine these two as such:
array([date] => "8/12/12", [rating] => 300, [rating2] => 600)
What would be the most effective way to do this?
You can use use +
sign on the array ...
$a = array("date" => "8/12/12","rating" => 300);
$b = array("date" => "8/12/12","rating2" => 600);
var_dump($a + $b);
Output
array
'date' => string '8/12/12' (length=7)
'rating' => int 300
'rating2' => int 600
Experiment with array_merge
and the +
operator
$a = array( 'key' => 'abc', 'foo' => true);
$b = array( 'key' => 'abc', 'bar' => true);
print_r( $a + $b );
print_r( array_merge( $a, $b ) );