September 12, 2013

PHP Array during echo

Anthonytherockjohnson’s Question:

I have an assignment to do but am having trouble understanding the given psuedocode :/

$bucket = new array();
print $bucket->addrocks('Rock1')->addrocks('rock2')-

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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!