Esempio n. 1
0
 function test_add_method()
 {
     $expected = array('surname' => 'Doe');
     $this->assertEquals($expected, Arr::add(array(), 'surname', 'Doe'));
     $this->assertEquals($expected, wpdevsclub_array_add(array(), 'surname', 'Doe'));
     $expected = array('developer' => array('name' => 'Tonya'));
     $this->assertEquals($expected, Arr::add(array(), 'developer.name', 'Tonya'));
     $this->assertEquals($expected, wpdevsclub_array_add(array(), 'developer.name', 'Tonya'));
     $data = array('foo' => 'foobar', 'bar' => 'barbar');
     $expected = array('foo' => 'foobar', 'bar' => 'barbar', 'baz' => 'bazbar');
     $this->assertEquals($expected, Arr::add($data, 'baz', 'bazbar'));
     $this->assertEquals($expected, wpdevsclub_array_add($data, 'baz', 'bazbar'));
 }
Esempio n. 2
0
 /**
  * Add an element to an array using "dot" notation if it doesn't exist.
  *
  * @param  array   $array
  * @param  string  $key
  * @param  mixed   $value
  * @return array
  */
 function wpdevsclub_array_add($array, $key, $value)
 {
     return Arr::add($array, $key, $value);
 }