i have the following array:
$list = array('item1','item2','item3','item4','item5','item6');
i need to take this array and break it into smaller arrays within 1 array for a program. Each small array needs to have ‘999999’ at index 0, followed by the next 2 items in the $list array, then followed by the same 2 items in the $list array, but with .pdf at the end, to create a filename. So the final result would be like this:
$newList = array( array(999999, "item1" , "item2", "item1.pdf", "item2.pdf"),
array(999999, "item3" , "item4", "item3.pdf", "item4.pdf"),
array(999999, "item5" , "item6", "item5.pdf", "item6.pdf")
);
the original list array may contain up to 100 values at sometimes. What is the best way to achieve this?
You can use
array_spliceto remove 2 elements at each iteration and build your results array. Something like that: