Initial array
Array
(
[0] => Array
(
[RecordDay] => 23
[Amount] => 1.50
[DocumentName] => bank stmt
[DocumentNumber] => 1
)
[1] => Array
(
[RecordDay] => 17
[Amount] => 0.21
[DocumentName] => invoice
[DocumentNumber] => 2
)
[2] => Array
(
[RecordDay] => 17
[Amount] => 1.00
[DocumentName] => invoice
[DocumentNumber] => 2
)
)
From all subarrays, where [RecordDay], [DocumentName] and [DocumentNumber] are the same want to create new array.
For keys [1] and [2] [RecordDay], [DocumentName] and [DocumentNumber] are the same.
So as a result want to get this
Array
(
[0] => Array
(
[RecordDay] => 23
[Amount] => 1.50
[DocumentName] => bank stmt
[DocumentNumber] => 1
)
)
Array
(
[0] => Array
(
[RecordDay] => 17
[Amount] => 0.21
[DocumentName] => invoice
[DocumentNumber] => 2
)
[1] => Array
(
[RecordDay] => 17
[Amount] => 1.00
[DocumentName] => invoice
[DocumentNumber] => 2
)
)
But no idea how to do that
Made like this
$first_loop = true;
foreach($initial_array as $key => $one_dimensional_array){
if($first_loop == true){
$new_array1['RecordDay'][] = $one_dimensional_array['RecordDay'];
$first_loop = false;
}
if($first_loop == false){
if( in_array( $one_dimensional_array['RecordDay'], $new_array1['RecordDay'] ) ){
$new_array1['RecordDay'][] = $one_dimensional_array['RecordDay'];
}
else{
$new_array2['RecordDay'][] = $one_dimensional_array['RecordDay'];
}
}//if($first_loop == false){
}//foreach($initial_array as $key => $one_dimensional_array){
Got
Array
(
[RecordDay] => Array
(
[0] => 23
[1] => 23
)
[DocumentName] => Array
(
[0] => bank stmt
[1] => bank stmt
)
[DocumentNumber] => Array
(
[0] => 1
[1] => 1
)
)
Array
(
[RecordDay] => Array
(
[0] => 17
[1] => 17
)
[DocumentName] => Array
(
[0] => invoice
[1] => invoice
)
[DocumentNumber] => Array
(
[0] => 2
[1] => 2
)
)
But this is not what want. Any ideas what need to change?