예제 #1
0
 private function prepareSequentialArray(&$value)
 {
     foreach ($value as $index => $subvalue) {
         if (is_object($subvalue) && !$subvalue instanceof Base) {
             $value[$index] = new self($subvalue);
         } elseif (is_array($subvalue)) {
             if (array_is_sequential($subvalue)) {
                 $value[$index] = $this->prepareSequentialArray($subvalue);
             }
         }
     }
     return $value;
 }
예제 #2
0
 /**
  * Re-order/re-index <optgroup> options.
  *
  * @param array $options    The select tag options(all).
  * @param array $subOptions The optgroup options.
  *
  * @return array
  */
 protected function organizeOptions(array $options, array $subOptions)
 {
     $indexedOptions = [];
     $convertedOptions = [];
     // Build the re-indexed options array.
     foreach ($options as $group) {
         foreach ($group as $i => $value) {
             // Check if sequential or not.
             if (array_is_sequential($group)) {
                 // Int values - Reorder options so there are
                 // no duplicates.
                 array_push($indexedOptions, $value);
             } else {
                 // Custom index or defined numeric indexes.
                 // Nothing to change.
                 $indexedOptions[$i] = $value;
             }
         }
     }
     // Grab the converted values and return them.
     foreach ($indexedOptions as $index => $option) {
         if (in_array($option, $subOptions)) {
             $convertedOptions[$index] = $option;
         }
     }
     return $convertedOptions;
 }