Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function parseDropdowns($raw_array)
- {
- /*$counter = 0;
- $splitCounter = 0;
- $last_read_dropdownId = FALSE;
- $new_array = array();
- $temp_array = array();
- $different = FALSE;
- foreach($raw_array as $element)
- {
- if(isset($element->dropdownsId) && !empty($element->dropdownsId)) {
- // does what we've read differ?
- if($last_read_dropdownId != $element->dropdownsId) {
- // update the last read with the value
- $last_read_dropdownId = $element->dropdownsId;
- // let us know how many unique dropdownIds were detected
- $splitCounter++;
- // add it to the temp array
- //$temp_array[] = (array)$element;
- //$new_array[$counter][] = $temp_array;
- $different = true;
- if(count($temp_array) == 0) {
- $new_array[] = $temp_array;
- }
- } else {
- $different = false;
- $temp_array[] = (array)$element;
- }
- if($different) {
- //$temp_array = (array)$element;
- //$new_array[] = $temp_array;
- } else {
- //$temp_array[] = (array)$element;
- }
- }
- $counter++;
- }
- echo "splitCounter: $splitCounter<br/>";
- echo "Counter: $counter<br/>";
- print_r($temp_array);
- print_r($new_array);
- die();
- return $new_array();*/
- $output = array();
- // Iterate over the main array and create a new subarray if
- // it doesn't already exist, or add to it if it does.
- foreach($raw_array as $subarr) {
- if (!isset($output[$subarr->dropdownsId])) {
- // New array indexed by sid
- $output[$subarr->dropdownsId] = array();
- }
- // Append the whole array
- $output[$subarr->dropdownsId][] = $subarr;
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement