note 46493 added to function.next

From: Date: Wed, 13 Oct 2004 08:47:21 +0000
Subject: note 46493 added to function.next
Groups: php.notes 
Request: Send a blank email to php-notes+get-78474@lists.php.net to get a copy of this message
I need to know if an array has more items, but without moving array's internail pointer. Thats is, a has_next() function: <?php function has_next($array) { if (is_array($array)) { if (next($array) === false) { return false; } else { return true; } } else { return false; } } $array = array('fruit', 'melon'); if (has_next($array)) { echo next($array); } // prints 'melon' ?> Since you do not pass the array by reference, its pointer is only moved inside the function. Hope that helps. ---- Manual Page -- http://www.php.net/manual/en/function.next.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46493 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46493&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46493&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46493&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46493&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46493&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46493&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46493&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78474) next »