示例#1
0
 /**
  * Tests Arr::isAssoc()
  *
  * @test
  * @dataProvider providerIsAssoc
  * @param array   $array     Array to check
  * @param boolean $expected  Is $array assoc
  */
 public function testIsAssoc(array $array, $expected)
 {
     $this->assertSame($expected, Arr::isAssoc($array));
 }
示例#2
0
 /**
  * Convert a multi-dimensional array into a single-dimensional array.
  *
  *     $array = array('set' => array('one' => 'something'), 'two' => 'other');
  *
  *     // Flatten the array
  *     $array = Arr::flatten($array);
  *
  *     // The array will now be
  *     array('one' => 'something', 'two' => 'other');
  *
  * [!!] The keys of array values will be discarded.
  *
  * @param  array $array array to flatten
  * @return array
  *                     @since   3.0.6
  */
 public static function flatten($array)
 {
     $is_assoc = Arr::isAssoc($array);
     $flat = [];
     foreach ($array as $key => $value) {
         if (is_array($value)) {
             $flat = array_merge($flat, Arr::flatten($value));
         } else {
             if ($is_assoc) {
                 $flat[$key] = $value;
             } else {
                 $flat[] = $value;
             }
         }
     }
     return $flat;
 }