Guest User

arrays

a guest
Jan 3rd, 2014
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.     include 'array.php';
  4.  
  5.     function ohoh($a, $needle)
  6.     {
  7.         $result = array();
  8.         $i = 0;
  9.         foreach($a as $key => $value)
  10.         {
  11.             foreach($value as $kv => $vv)
  12.             {
  13.                 preg_match("(.*title|.*content)", $kv, $res);
  14.                 if(count($res))
  15.                 {
  16.                     $result[$i][$res[0]] = $vv;
  17.                     if(strstr($res[0], 'content')) $i++;
  18.                 }
  19.                
  20.                 preg_match('/(grid_num|cells_num|cell_weight)/', $kv, $rs);
  21.                 if(count($rs) > 0) $result[$kv] = $vv;
  22.             }
  23.         }
  24.  
  25.         return $result;
  26.     }
  27.  
  28.     function fire($a, $keys)
  29.     {
  30.         $length = count($a) / $keys;
  31.         $arrays = array_chunk($a, $length);
  32.         $result = array();
  33.  
  34.         $i = 0;
  35.         foreach($arrays as $array)
  36.         {
  37.             $result[]['tabs'] = ohoh($array, $i);
  38.             $i++;
  39.         }
  40.  
  41.         return $result;
  42.     }
  43.  
  44.     $keys = 2;
  45.  
  46.     echo "<pre>";
  47.     print_r(fire($a, $keys));
  48.     echo "</pre>";
  49.  
  50.  
  51.  
  52. /**
  53.  
  54. # contents of array.php
  55.  
  56. $a = array(
  57.     0 => array('tab-title-rEXMp' => 'tab-1'),
  58.     1 => array('tab-content-rEXMp' => 'tab-1 content'),
  59.     2 => array('tab-title-rEXMp' => 'tab-2'),
  60.     3 => array('tab-content-rEXMp' => 'tab-2 content'),
  61.     4 => array('tab-title-rEXMp' => 'tab-3'),
  62.     5 => array('tab-content-rEXMp' => 'tab-3 content'),
  63.     6 => array('cells_num' => 1),
  64.     7 => array('grid_num' => 0),
  65.     8 => array('cell_weight' => '100%'),
  66.     9 => array('tab-title-3T2IV' => 'tab-4'),
  67.     10 => array('tab-content-3T2IV' => 'tab-4 content'),
  68.     11 => array('tab-title-3T2IV' => 'tab-5'),
  69.     12 => array('tab-content-3T2IV' => 'tab-5 content'),
  70.     13 => array('tab-title-3T2IV' => 'tab-6'),
  71.     14 => array('tab-content-3T2IV' => 'tab-6 content'),
  72.     15 => array('cells_num' => 1),
  73.     16 => array('grid_num' => 1),
  74.     17 => array('cell_weight' => '100%')
  75. );
  76.  
  77. */
RAW Paste Data