php - Array merge at second level -
i have 2 arrays shown below. need merge content of arrays can structure shown in third array @ last. have checked array_merge can't figure out way possible. appreciated. thanks.
array( (int) 0 => array( 'gross_value' => '100', 'quantity' => '1' ), (int) 1 => array( 'gross_value' => '200', 'quantity' => '1' ) ) array( (int) 0 => array( 'item_title_id' => '1', 'order_id' => '4' ), (int) 1 => array( 'item_title_id' => '2', 'order_id' => '4' ) )
i should merged array this
array( (int) 0 => array( 'gross_value' => '100', 'quantity' => '1', 'item_title_id' => '1', 'order_id' => 4 ), (int) 1 => array( 'gross_value' => '200', 'quantity' => '1', 'item_title_id' => '2', 'order_id' => 4 )
)
use array_merge_recursive :
convert numeric key strings, (make associative array)
$result = array_merge_recursive($ar1, $ar2); print_r($result);
see live demo here
Comments
Post a Comment