PHP Array during echo
Anthonytherockjohnson’s Question:
I have an assignment to do but am having trouble understanding the given psuedocode :/
<?php
$bucket = new array();
print $bucket->addrocks('Rock1')->addrocks('rock2')-
>addrocks('Rock3');
echo "<h1>My Bucket</h1>";
echo "<ul>";
foreach($bucket as $rock){
echo "<li>". $rock ."</li>";
}
echo "</ul>";
?>
Now my trouble starts with understanding how they want me to construct the array after the “print” call? i am not looking for a direct answer to this just maybe a tutorial link or a finger in the right direction
Thank you in advance
Well unlikely but may be the array
is not an construct but an class in your pseudocode. My assumptions depend on the use of new
keyword and the user of ->
and addrocks
which looks like a method.
So, create a class called array
(stupid I know) and get going.
However the user of foreach($bucket)
also shows that it expects $bucket to be array. So decide wisely 🙂
May be use a magic method called __toString()
inside the class and return back the array.