Jump to content

Basic array using end and while


suttercain

Recommended Posts

Hello and good weekend!

 

I am reading a PHP book and in one of the tutorials that deals with arrays they provid the following code:

 

<?php
$numbers = array("one", "two", "three", "four");
$item = current($numbers);
do
{
echo "$item ";
}
while (($item = next($numbers)) !== FALSE);
echo "<br/> \n";
end($drinks);
while (($item = prev($drinks)) !== FALSE)
{
echo "$item<br/>\n";
}
?>

 

When I run it locally on my apache server I get the following:

 

one two three four

 

Warning: end() [function.end]: Passed variable is not an array or object in D:\wamp\www\PHP Tutorials\arrays.php on line 10

 

Warning: prev() [function.prev]: Passed variable is not an array or object in D:\wamp\www\PHP Tutorials\arrays.php on line 11

 

When it actually shoud print:

 

one two three four

four three two one

 

 

Where is the error? Thanks in advance.

 

Shannon

Link to comment
https://forums.phpfreaks.com/topic/39073-basic-array-using-end-and-while/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.