How can i get seperate values of array into same array?
I have a PHP array that I am trying to split into 2 different arrays into that particular array. I am trying to pull out any values for each "destination" and "balance".
Here is the array i get,
Array ( [destination_1] => 1 [balance_1] => 1 [destination_2] => 2 [balance_2] => 2 [destination_3] => 3 [balance_3] => 3 )
I need output like,
Array ( [0] => Array ( [destination_1] => 1 [balance_1] => 1 ) [1] => Array ( [destination_2] => 2 [balance_1] => 2 ) [2] => Array ( [destination_3] => 3 [balance_3] => 3 ) )
What you need is array_chunk()
$arr = [ "destination_1" => 1, "balance_1" => 1, "destination_2" => 2, "balance_2" => 2, "destination_3" => 3, "balance_3" => 3 ]; $result = array_chunk($arr, 2, true);
Output:
Array ( [0] => Array ( [destination_1] => 1 [balance_1] => 1 ) [1] => Array ( [destination_2] => 2 [balance_2] => 2 ) [2] => Array ( [destination_3] => 3 [balance_3] => 3 ) )