I have found many post related to array_slice, but none re: a nested array that mirrors this. I have an array:
array (
Key1 => values,
Key2 => array[0] =>
Keys => values,
Key3 => array[0]=>
Keys => values,
Key4 => array[0] // Key = LineItems
Key => array[0]
keys => values,
Key => array[0]
Keys => values,
Key => array[0]
Keys => values,
Key => array[1]
Keys => Values
Key => array[0]
Keys => values,
Key => array[0]
Keys => values,
Key => array[0]
Keys => values,
Key5 => array[0] // Key = AddressRepository
keys =>values,
)
I need to slice it and return this:
Key4 => array[0]
Key => array[0]
keys => values,
Key => array[0]
Keys => values,
Key => array[0]
Keys => values,
Key => array[1]
Keys => Values
Key => array[0]
Keys => values,
Key => array[0]
Keys => values,
Key => array[0]
Keys => values,
I am able to return array[4][0][0] and [4][1][0] using this function (I'm using key names for array[4] and array[5] since it's associative) but not the sub-arrays:
function sliceLineItems($array) {
$start = array_search('LineItems', array_keys($array));
echo $start;flush();
$end = (array_search('AddressRepository', $array)-1);
$slicedLineItems = array_slice($array, $start, $end, true);
return $slicedLineItems;
}
I need all of the sub-arrays in Key4.