I am using list and array_chunk to split arrays. In my first example I split the array into four pieces using list.
I would like to change the number from 4 to say 8 and have it dynamically do this. Instead of manually creating it in the code. Is this possible ? I assume I could use variable naming as listed in my non working second example below.
How it works now :
list($inv0, $inv1, $inv2, $inv3) = array_chunk($val['inventory'], ceil(count($val['inventory']) / 4));
What I would like is to set something $i = 8 and have it automatically split into 8 chunks dynamically .
Something like :
$i = 8
list(${inv.0}, ${inv.1}, ${inv.2}, ${inv.3},${inv.4},${inv.5},${inv.6},${inv.7}) = array_chunk($val['inventory'], ceil(count($val['inventory']) / $i));
So based on my needs I can split the array into X pieces instead of hard coding it to 4 or 8 etc...