我发现很多与array_slice相关的帖子,但没有一个:一个镜像这个的嵌套数组。我有一个数组:
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,
)
我需要将其切片并返回:
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,
我可以使用这个函数返回数组[4] [0] [0]和[4] [1] [0](我使用数组[4]和数组[5]的键名,因为它是关联)但不是子数组:
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;
}
我需要Key4中的所有子数组。