My array looks like this:
array(4) (
0 => array(3) (
"id" => string(1) "2"
"state" => string(8) "San Francisco"
"options" => array(2) (
"value" => string(1) "1"
"label" => string(8) "SF1"
)
)
1 => array(3) (
"id" => string(1) "2"
"state" => string(8) "San Francisco"
"options" => array(2) (
"value" => string(1) "2"
"label" => string(6) "SF2"
)
)
2 => array(3) (
"id" => string(1) "1"
"state" => string(7) "New Jersey"
"options" => array(2) (
"value" => string(1) "3"
"label" => string(9) "NJ1"
)
)
3 => array(3) (
"id" => string(1) "1"
"state" => string(7) "New Jersey"
"options" => array(2) (
"value" => string(1) "4"
"label" => string(10) "NJ2"
)
)
)
What I want to achieve is get an array with the options added on duplicate state names. So that I end up with San Francisco options having 2 arrays in it and so on for any other duplicate state names I get.
How do I do this in php?
What I would like to have is:
Combine the arrays so that the "options" part of "state" has the multiples. For example "San Franciso" would have its Options section as 2 arrays with SF1 and SF2. I hope that is clear.
I think you need something similar:
$output_array = array();
foreach($input_array as $input){
$output_array[$input['state']][] = $input;
}