daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Sep 18th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Array
  2. (
  3.     [0] => Array
  4.     (
  5.         [id] => 3
  6.         [title] => One
  7.         [count] => 2
  8.     )
  9.  
  10.     [1] => Array
  11.     (
  12.         [id] => 7
  13.         [title] => Two
  14.         [count] => 3
  15.     )
  16.  
  17.     [2] => Array
  18.     (
  19.         [id] => 5
  20.         [title] => Three
  21.         [count] => 2
  22.     )
  23.  
  24.     [3] => Array
  25.     (
  26.         [id] => 8
  27.         [title] => Four
  28.         [count] => 22
  29.     )
  30.  
  31.     [4] => Array
  32.     (
  33.         [id] => 9
  34.         [title] => Five
  35.         [count] => 14
  36.     )
  37.  
  38.     [5] => Array
  39.     (
  40.         [id] => 11
  41.         [title] => Six
  42.         [count] => 7
  43.     )
  44. )
  45.    
  46. Array
  47. (
  48.     [0] => Array
  49.     (
  50.         [id] => ['3','7','5']
  51.         [count] => 7
  52.         [offset] => 0
  53.     )
  54.  
  55.     [1] => Array
  56.     (
  57.         [id] => ['11']
  58.         [count] => 7
  59.         [offset] => 0
  60.     )
  61.  
  62.     [2] => Array
  63.     (
  64.         [id] => ['9']
  65.         [count] => 14
  66.         [offset] => 0
  67.     )
  68.  
  69.     [3] => Array
  70.     (
  71.         [id] => ['9']
  72.         [count] => 14
  73.         [offset] => 10
  74.     )
  75.  
  76.     [4] => Array
  77.     (
  78.         [id] => ['8']
  79.         [count] => 22
  80.         [offset] => 0
  81.     )
  82.  
  83.     [5] => Array
  84.     (
  85.         [id] => ['8']
  86.         [count] => 22
  87.         [offset] => 10
  88.     )
  89.  
  90.     [6] => Array
  91.     (
  92.         [id] => ['8']
  93.         [count] => 22
  94.         [offset] => 20
  95.     )
  96.  
  97.     [7] => Array
  98.     (
  99.         [id] => ['8']
  100.         [count] => 22
  101.         [offset] => 30
  102.     )
  103. )
  104.    
  105. $groups = array();
  106. foreach ($array as $key => $item)
  107. {
  108.     if ($item['count'] < 10)
  109.     {
  110.         array_push($groups, [
  111.             'id' => [$item['id']],
  112.             'count' => $item['count'],
  113.             'offset' => 0
  114.         ]);
  115.     }
  116.     else
  117.     {
  118.         // Increase by 10 for offset fetch implementation
  119.         for ($i=0; $i < ($item['count'] + 10); $i+=10)
  120.         {
  121.             array_push($groups, [
  122.                 'id' => [$item['id']],
  123.                 'count' => $item['count'],
  124.                 'offset' => $i
  125.             ]);
  126.         }
  127.     }
  128. }
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