Returns a DataTable from a simple matrix (array of array, with first row = label if hasHeader = true)
@param array $array
@param boolean $hasHeader if true, indicates that the first row contains the labels
@return DataTable
976818
public static function fromSimpleMatrix(array $array, $hasHeader = true) {
        $dataTable = new DataTable();
        
        $labelArray = array();
        if ($hasHeader) {
            $labelArray = $array[0];
            array_shift($array);
            
        }
        //need to found out the data type... just string or number
        $firstDataRow = $array[0];
        foreach ($firstDataRow as $key => $value) {
            $type = "string";
            $label = isset($labelArray[$key])? $labelArray[$key]: 'c'.$key;
            if (is_object($value) && $value instanceof \DateTime) {
                $type = 'datetime';
            } elseif (is_bool($value)) {
                $type = 'boolean';
            } elseif (is_numeric($value)) {
                $type = 'number';
            }
            $dataTable->addColumn('id'.$key, $label, $type);
        }
        //now the data...
        foreach ($array as $key => $row) {
                $dataTable->addRow($row);
        }
        return $dataTable;
        
        
    }
456640
public function groupBy($array, $columns)
    {
        // ensure $columns parameter is array
        $columns = (array) $columns;

        // get first group-by column
        $col = array_shift($columns);

        $result = array();
        foreach ($array as $row) {
            $key = (string) is_object($row) ? $row->$col : $row[$col];
            if (!isset($result[$key])) {
                $result[$key] = array();
            }

            $result[$key][] = $row;
        }

        // do subsequent group by calls
        if (count($columns)) {
            foreach (array_keys($result) as $key) {
                $result[$key] = $this->groupBy($result[$key], $columns);
            }
        }

        return $result;
    }
934802
public static function array_flip2( $array )
	{
		$result = array();
		foreach ( $array as $key => $value )
		{
			if ( isset( $result[ $value ] ) && in_array( $key, $result[ $value ] ) ) continue;
			$result[ $value ][] = $key;
		}
		return $result;
	}
731749
public function only(array $array)
  {
    $data = [];

    foreach($array as $field) {
      if ($this->has($field)) {
        $data[$field] = $this->data[$field];
      }
    }

    return $data;
  }
337076
public static function array_flatten(array $array){
		$index = 0;
		$count = count($array);

		while ($index < $count) {
			if (is_array($array[$index])) {
				array_splice($array, $index, 1, $array[$index]);
			} else {
				++$index;
			}
			$count = count($array);
		}
		return $array;
	}
354581
protected function doCreateObject(array $array)
    {
        $orderItem = new OrderItem(isset($array['attributes']) && is_array($array['attributes']) ? $array['attributes'] : $array);
        if (isset($array['relationships']['products'])) {
            $mapper = new ProductsMapper();
            foreach ($array['relationships']['products'] as $item) {
                $product            = array_merge($item['attributes'], $item['relationships']);
                $orderItem->product = $mapper->createObject($product);
            }
        }

        // old structure
        if (isset($array['products'][0])) {
            if (isset($array['images'])) {
                $array['products'][0]['images'] = $array['images'];
            }
            $productMapper      = new ProductsMapper();
            $orderItem->product = $productMapper->createObject($array['products'][0]);
        }

        return $orderItem;
    }
948047
protected function serializeArray(array $array) {
        $data = [];

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $data[$key] = $this->serializeArray($value);
            } else {
                $data[$key] = $this->serializeItem($value);
            }
        }

        return $data;
    }
826991
public static function writeAssociativeArrayTable(SymfonyStyle $helper, $array, $flatten = null)
    {
        if (null !== $flatten) {
            $helper->note('Using flatten is deprecated');

        }
        if (false === is_array($array)) {
            $helper->error(
                [
                    'Expecting associative array for table',
                    sprintf('Given data for table is %s.', gettype($array)),
                ]
            );
        }

        $rows = [];
        foreach ($array as $index => $value) {
            $rows[] = [
                $index,
                self::getStringForTable($value),
            ];
        }

        try {
            $helper->table([], $rows);
        } catch (ContextErrorException $error) {
            print_r($rows);

            $helper->error(
                [
                    'Table failed with error:',
                    $error->getMessage(),
                ]
            );
        }
    }
952847
public function stdClassToArrayCheckValues(array $array)
    {
        foreach ($array as $key => $value) {
            if ($value instanceof \stdClass) {
                $array[ $key ] = $this->stdClassToArray($value);
            } else if (is_array($value)) {
                $array[ $key ] = $this->stdClassToArrayCheckValues($value);
            } else {
                $array[ $key ] = $value;
            }
        }

        return $array;
    }
934334
public function getArrayLevel($array)
	{
		$n=1;
		foreach ($array as $item) {
			if(is_array($item)){
				$n=$this->getArrayLevel($item)+1;
			}
		}
		return $n;

	}
338184
public static function fromArray(array $array)
    {
        $hostname       = $array['hostname'] ?? null;
        $challengeTs    = $array['challenge_ts'] ?? null;
        $apkPackageName = $array['apk_package_name'] ?? null;
        $score          = isset($array['score']) ? floatval($array['score']) : null;
        $action         = $array['action'] ?? null;

        if (isset($array['success']) && $array['success'] == true)
            return new static(true, [], $hostname, $challengeTs, $apkPackageName, $score, $action);

        if ( ! (isset($array['error-codes']) && is_array($array['error-codes'])))
            $array['error-codes'] = [ResponseV3::E_UNKNOWN_ERROR];

        return new static(false, $array['error-codes'], $hostname, $challengeTs, $apkPackageName, $score, $action);
    }
1370069
public static function createFromArray(array $array): self
    {
        $hashMap = new self;

        foreach ($array as $key => $value) {
            $hashMap->put($key, $value);
        }

        return $hashMap;
    }
621088
public static function byPdfArray($array, PdfParser $parser)
    {
        $array = PdfArray::ensure(PdfType::resolve($array, $parser), 4)->value;
        $ax = PdfNumeric::ensure(PdfType::resolve($array[0], $parser))->value;
        $ay = PdfNumeric::ensure(PdfType::resolve($array[1], $parser))->value;
        $bx = PdfNumeric::ensure(PdfType::resolve($array[2], $parser))->value;
        $by = PdfNumeric::ensure(PdfType::resolve($array[3], $parser))->value;

        return new self($ax, $ay, $bx, $by);
    }
896205
public static function convertArrayToFlatTextArray(array $array) {
    $rows = [];
    $max_line_length = 60;
    foreach ($array as $key => $value) {
      if (is_array($value)) {
        $flattened_array = self::flattenToDotNotatedKeys($value);
        foreach ($flattened_array as $sub_key => $sub_value) {
          if ($sub_value === TRUE) {
            $sub_value = 'true';
          }
          elseif ($sub_value === FALSE) {
            $sub_value = 'false';
          }
          $rows[] = [
            "$key.$sub_key",
            wordwrap($sub_value, $max_line_length, "\n", TRUE),
          ];
        }
      }
      else {
        if ($value === TRUE) {
          $contents = 'true';
        }
        elseif ($value === FALSE) {
          $contents = 'false';
        }
        else {
          $contents = wordwrap($value, $max_line_length, "\n", TRUE);
        }
        $rows[] = [$key, $contents];
      }
    }

    return $rows;
  }
649750
public function arrayToUnorderedList(array $array): string
    {
        $out = '<ul>';
        foreach ($array as $key => $elem) {
            if (!is_array($elem)) {
                $out = $out . "<li><span>{$key}: " . h($elem) . '</span></li>';
            } else {
                $out = $out . "<li><span>{$key}</span>" . $this->arrayToUnorderedList($elem) . '</li>';
            }
        }
        $out .= '</ul>';

        return $out;
    }
49997
public static function createFromArray(array $array)
    {
        self::$instance = new Collector;

        self::$instance->buffer = null;

        $spreadsheet = new Spreadsheet();
        $spreadsheet->getActiveSheet()
            ->fromArray(
                $array,  // os dados a adicionar
                NULL     // itens com este valor não serão setados
            );

        self::$instance->buffer = $spreadsheet;

        self::$instance->debug_info = ['created_with' => __METHOD__];

        return self::$instance;
    }
369123
private function serializeArrayRecursively(array $array): array
    {
        $data = [];
        foreach ($array as $key => $value) {
            $data[$key] = $this->serializeValue($value);
        }

        return $data;
    }