SHARE
TWEET

Untitled

a guest Jun 16th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function chunk($text, $parts) {
  2.     $partSize = strlen($text)/$parts;
  3.     $tailSize = strlen($text)%$parts;
  4.     $arr = [];
  5.     for ($i = 0; $i < $parts; $i++) {
  6.         array_push($arr, substr($text, $i*$partSize, $partSize));
  7.     }
  8.     // Хвост
  9.     if ($tailSize != 0) {
  10.         $end = substr($text, $parts*$partSize + 1, $tailSize);
  11.         array_push($arr, $end);
  12.     }
  13.     return $arr;
  14. }
  15.      
  16. json_encode(chunk('hellohellohello', 4))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top