suttercain Posted February 18, 2007 Share Posted February 18, 2007 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 More sharing options...
printf Posted February 18, 2007 Share Posted February 18, 2007 There is no array() called $drinks! So how can end(); move to the last key, if the array doesn't exist! printf Link to comment https://forums.phpfreaks.com/topic/39073-basic-array-using-end-and-while/#findComment-188181 Share on other sites More sharing options...
LazyJones Posted February 18, 2007 Share Posted February 18, 2007 pretty sure it should be end($numbers).... no more drinks for you! Link to comment https://forums.phpfreaks.com/topic/39073-basic-array-using-end-and-while/#findComment-188184 Share on other sites More sharing options...
suttercain Posted February 18, 2007 Author Share Posted February 18, 2007 Good looking out. For anyone interested: That mistake is on page 123 of "Web Application and Development with PHP and MYSQL" Thanks. Link to comment https://forums.phpfreaks.com/topic/39073-basic-array-using-end-and-while/#findComment-188186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.