我有一個多維數組是這樣的:轉換多維數組到XML對象在PHP
$array = array(
"hello" => "hola",
"another_array" => array(
"key" => "best key ever",
"another" => "yes, another key",
),
"coolarray" => array(
"bool" => true,
"string" => "this is a string!",
),
);
我想這樣的一個類:
class MyClass {
public $array;
public function __construct($array) {
// something
$this->array_to_xml($array);
}
public function array_to_xml($array) {
// convert array to xml
}
然後,我希望能夠做到像這樣的事情:
$string = $this->array->coolarray->string;
我該怎麼做?
@Martijn我已經在嘗試的答案3,我仍然不知道如何使用它作爲這樣一個對象:'$ string = $ this-> array-> coolarray-> string;' – James