function _flatten($array, $shallow = false)
{
    return Underscore::flatten($array, $shallow);
}
Exemplo n.º 2
0
 /**
  * @tags arrays
  */
 public function testFlatten()
 {
     // it should flatten arrays
     $this->array(_::flatten([[1], [2], [3]]))->isEqualTo([1, 2, 3]);
     $this->array(_::flatten([[1, 2], [3, 4]]))->isEqualTo([1, 2, 3, 4]);
     // it should deep-flatten arrays by default
     $this->array(_::flatten([[[1]], [[2]], [[3]]]))->isEqualTo([1, 2, 3]);
     // it should be possible to obtain a shallow copy
     $this->array(_::flatten([[[1]], [[2]], [[3]]], true))->isEqualTo([[1], [2], [3]]);
     // it should work on arrays objects an iterators
     $this->typeTolerant([[1, 2], [3, [4]]], [1, 2, 3, 4], function ($in, $out) {
         $this->array(_::flatten($in))->isEqualTo($out);
     }, [1, -1]);
     // it should return an empty array if list is empty
     $this->array(_::flatten(null))->isEqualTo([]);
 }