I am trying to convert class to array. I am using following code:
class Abc{
private $x, $y, $z;
protected $x1, $y1, $z1;
protected $x2, $y2, $z2;
public function __construct() {
$this->x=$this->y=$this->z=$this->x1=$this->y1=$this->z1=$this->x2=$this->y2=$this->z2=0;
}
public function getData() {
return $x;
}
public function toArray() {
return (array)$this;
}
}
$abc = new Abc();
echo '<pre>', print_r($abc->toArray(), true), '</pre>';
Now the weird thing is the output:
Array
(
[Propertyx] => 0
[Propertyy] => 0
[Propertyz] => 0
[*x1] => 0
[*y1] => 0
[*z1] => 0
[*x2] => 0
[*y2] => 0
[*z2] => 0
)
I want clean keys with no Class name and no * before key names.
Can anyone suggest me how to convert members names into array keys without class name and and without (*). Other solutions are also welcome.
print_r, as the OP usetrueinprint_r, theprint_rdisplay the information with the array.