I have two array
:
$data1 = array(
(0) => array("level" => 1, "id" => 1, "index" => 1, "amount" => 50000),
(1) => array("level" => 1, "id" => 2, "index" => 1, "amount" => 40000),
(2) => array("level" => 1, "id" => 3, "index" => 1, "amount" => 0));
$data2 = array(
(0) => array("level" => 2, "id" => 1, "index" => 1, "amount" => 30000),
(1) => array("level" => 2, "id" => 1, "index" => 2, "amount" => 20000),
(2) => array("level" => 2, "id" => 2, "index" => 1, "amount" => 15000),
(3) => array("level" => 2, "id" => 2, "index" => 2, "amount" => 25000),
(4) => array("level" => 2, "id" => 3, "index" => 1, "amount" => 0));
I want to merge those array into one array and the result is like this :
$expected = array(
(0) => array("level" => 1, "id" => 1, "index" => 1, "amount" => 50000),
(1) => array("level" => 2, "id" => 1, "index" => 1, "amount" => 30000),
(2) => array("level" => 2, "id" => 1, "index" => 2, "amount" => 20000),
(3) => array("level" => 1, "id" => 2, "index" => 1, "amount" => 40000),
(4) => array("level" => 2, "id" => 2, "index" => 1, "amount" => 15000),
(5) => array("level" => 2, "id" => 2, "index" => 2, "amount" => 25000));
I've tried to use array_merge_recursive :
$try = array_merge_recursive($data1, $data2);
But the result is like this :
$try = array(
(0) => array("level" => 1, "id" => 1, "index" => 1, "amount" => 50000),
(1) => array("level" => 1, "id" => 2, "index" => 1, "amount" => 40000),
(3) => array("level" => 1, "id" => 3, "index" => 1, "amount" => 0),
(4) => array("level" => 2, "id" => 1, "index" => 1, "amount" => 30000),
(5) => array("level" => 2, "id" => 1, "index" => 2, "amount" => 20000),
(6) => array("level" => 2, "id" => 2, "index" => 1, "amount" => 15000),
(7) => array("level" => 2, "id" => 2, "index" => 2, "amount" => 25000),
(8) => array("level" => 2, "id" => 3, "index" => 1, "amount" => 0));
I have criteria for my result :
- Remove array where amount=0
- Sort and order by id,level,index
I've read about uasort and usort but i dont have any idea how to implement that function to match what i need. Is that function (uasort/usort) can solve it or any other idea? Please help me, thanks!