I want to cast a Object to an array, so i can iterate with an loop over it.
I know that:
$array = (array) $object
exists. But I want something like the custom
__toString()
method for arrays.
I know so far that
__toArray()
does not exist.
Question:
Can I create this magic method customly and how?
(I'm also aware of the fact, that i could work around this by just calling a function that returns an array)
I want to cast the Object to an custom array:
foreach($object as $key=>$value) {}
not converting it by calling a function
foreach($object->toArray as $key=>$value){}
even if it would be the simplest way ...