Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function chunk($text, $parts) {
- $partSize = strlen($text)/$parts;
- $tailSize = strlen($text)%$parts;
- $arr = [];
- for ($i = 0; $i < $parts; $i++) {
- array_push($arr, substr($text, $i*$partSize, $partSize));
- }
- // Хвост
- if ($tailSize != 0) {
- $end = substr($text, $parts*$partSize + 1, $tailSize);
- array_push($arr, $end);
- }
- return $arr;
- }
- json_encode(chunk('hellohellohello', 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement