function - Failed Using array_merge inside of PHP class -


class test {   public $data = array();    public function adddata($data = array())   {     array_merge($data, $this->data);     return $this;   }    public function showdata()   {     print_r($this->data);   } } $test = new test; $test->adddata(array("halo", "zaki"))->showdata(); 

i tried merging 2 array, doesn't work, maybe can explain me?

you forgot assign resulting array member variable $data. should be,

$this->data = array_merge($data, $this->data); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -