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
Post a Comment