I have an array similar to this:
array(
array(
'id' => 'a',
'other' => 'abc: ',
'subarray' => array(
'somekey' => 'abc',
),
'subarray2' => array(
'somekey' => 'abc',
),
),
array(
'id' => 'b',
'other' => 'abc: ',
'subarray' => array(
'somekey' => 'abc',
),
),
array(
'id' => 'c',
'other' => 'abc: ',
'subarray' => array(
'somekey' => 'abc',
),
),
)
I need to be able to copy each sub array into a new array by matching the ID. So, let's say I need to match ID 'b'.
The code I ended up using was a foreach loop to loop the array and find my id, then using the key from the parent array to copy the values of the subarray:
$value = 'b'
foreach ($this->fields as $fields_array => $sub_array) {
if ( $sub_array['id'] == $value ) {
$new_array = $this->fields[$fields_array];
//do something with new array
}
}