Skip to navigation
Split a integer in equal chunks and give it back as array in php
20.10.15
function split_number($number,$div) { $arr = []; if((int)$number > 0 && (int)$div > 0): if($number <= $div): $arr[] = $number; return $arr; endif; $extra = $number%$div; $rest = $number-$extra; $qty = ($rest/$div); for($x=1;$x<=$qty;$x++): $arr[] = $div; endfor; if($extra): $arr[] = $extra; endif; endif; return $arr; }
http://php.net/manual/en/refs.basic.vartype.php
Reply
Anonymous
Information Epoch 1740242587
Distrust all claims for one true way.
Home
Notebook
Contact us