Here is the array, which I have posted through Ajax and get into the ajax.php file. Now i want to add a new array, as shown below.
Array
(
[0] => Array
(
[contact_id] => 5000
[invoice] => 476
)
[1] => Array
(
[contact_id] => 5000
[invoice] => 396
)
[2] => Array
(
[contact_id] => 1490
[invoice] => 1083
)
[3] => Array
(
[contact_id] => 1490
[invoice] => 498
)
)
I also want to add this if contact id are same, then invoice will be added
Array
(
[0] => Array
(
[contact_id] => 5000
[invoice] => Array (
[0] =>476,
[1] =>396
)
)
[2] => Array
(
[contact_id] => 1490
[invoice] => Array (
[0] =>1083,
[1] =>498
)
)
)
I tried to do it, without success. Here is my code:
$invtemp =array();
foreach($_POST['invoice_id'] as $value){
if(!in_array($value['contact_id'], $invtemp, true)){
$arr = array($value['contact_id'] => $value['invoice'] );
array_push($invtemp, $arr);
}
}