Exemplo n.º 1
0
 /**
  * Tests Arr::setPath()
  *
  * @test
  * @dataProvider providerSetPath
  * @param string  $path       The path to follow
  * @param boolean $expected   The expected value
  * @param string  $delimiter  The path delimiter
  */
 public function testSetPath($expected, $array, $path, $value, $delimiter = null)
 {
     Arr::setPath($array, $path, $value, $delimiter);
     $this->assertSame($expected, $array);
 }
Exemplo n.º 2
0
 /**
  * Retrieves multiple paths from an array. If the path does not exist in the
  * array, the default value will be added instead.
  *
  *     // Get the values "username", "password" from $_POST
  *     $auth = Arr::extract($_POST, array('username', 'password'));
  *
  *     // Get the value "level1.level2a" from $data
  *     $data = array('level1' => array('level2a' => 'value 1', 'level2b' => 'value 2'));
  *     Arr::extract($data, array('level1.level2a', 'password'));
  *
  * @param  array $array   array to extract paths from
  * @param  array $paths   list of path
  * @param  mixed $default default value
  * @return array
  */
 public static function extract($array, array $paths, $default = null)
 {
     $found = [];
     foreach ($paths as $path) {
         Arr::setPath($found, $path, Arr::path($array, $path, $default));
     }
     return $found;
 }