Advertisement
Guest User

Untitled

a guest
Apr 7th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. private function parseDropdowns($raw_array)
  2.     {
  3.         /*$counter = 0;
  4.         $splitCounter = 0;
  5.         $last_read_dropdownId = FALSE;
  6.         $new_array = array();
  7.         $temp_array = array();
  8.         $different = FALSE;
  9.         foreach($raw_array as $element)
  10.         {
  11.             if(isset($element->dropdownsId) && !empty($element->dropdownsId)) {
  12.                 // does what we've read differ?
  13.                 if($last_read_dropdownId != $element->dropdownsId) {
  14.                     // update the last read with the value
  15.                     $last_read_dropdownId = $element->dropdownsId;
  16.                     // let us know how many unique dropdownIds were detected
  17.                     $splitCounter++;
  18.                     // add it to the temp array
  19.                     //$temp_array[] = (array)$element;
  20.                     //$new_array[$counter][] = $temp_array;
  21.                    
  22.                     $different = true;
  23.                     if(count($temp_array) == 0) {
  24.                         $new_array[] = $temp_array;
  25.                     }
  26.                 } else {
  27.                     $different = false;
  28.                     $temp_array[] = (array)$element;
  29.                 }
  30.                
  31.                 if($different) {
  32.                     //$temp_array = (array)$element;
  33.                     //$new_array[] = $temp_array;
  34.                 } else {
  35.                     //$temp_array[] = (array)$element;
  36.                 }
  37.                
  38.             }
  39.             $counter++;
  40.         }
  41.        
  42.         echo "splitCounter: $splitCounter<br/>";
  43.         echo "Counter: $counter<br/>";
  44.        
  45.         print_r($temp_array);
  46.         print_r($new_array);
  47.         die();
  48.         return $new_array();*/
  49.         $output = array();
  50.  
  51.         // Iterate over the main array and create a new subarray if
  52.         // it doesn't already exist, or add to it if it does.
  53.         foreach($raw_array as $subarr) {
  54.             if (!isset($output[$subarr->dropdownsId])) {
  55.                 // New array indexed by sid
  56.                 $output[$subarr->dropdownsId] = array();
  57.             }
  58.             // Append the whole array
  59.             $output[$subarr->dropdownsId][] = $subarr;
  60.         }
  61.        
  62.         return $output;
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement