note 92301 added to function.current

From: Date: Sat, 18 Jul 2009 00:27:59 +0000
Subject: note 92301 added to function.current
Groups: php.notes 
Request: Send a blank email to php-notes+get-158445@lists.php.net to get a copy of this message
**Apologies. Please ignore or remove my previous note. This version allows for false values in the array.** In the rare need for look-ahead and look-behind ability while looping through an array, you can use prev(), next() and current() like so: <?php $nums = array('a','b','c',false,'e', 'f'); for(reset($nums), $i=0; $n=current($nums), key($nums)!==null; next($nums), $i++){ // look behind $behind=' '; if($i>0){ $n=prev($nums); $behind=$n; $n=next($nums); } // look ahead $ahead=' '; next($nums); if(key($nums)!==null){ $ahead=current($nums); } prev($nums); echo "$i: $behind $n $ahead\n"; } ?> Results: 0: a b 1: a b c 2: b c 3: c e 4: e f 5: e f ---- Server IP: 69.147.83.197 Probable Submitter: 24.251.157.169 ---- Manual Page -- http://www.php.net/manual/en/function.current.php Edit -- https://master.php.net/note/edit/92301 Del: integrated -- https://master.php.net/note/delete/92301/integrated Del: useless -- https://master.php.net/note/delete/92301/useless Del: bad code -- https://master.php.net/note/delete/92301/bad+code Del: spam -- https://master.php.net/note/delete/92301/spam Del: non-english -- https://master.php.net/note/delete/92301/non-english Del: in docs -- https://master.php.net/note/delete/92301/in+docs Del: other reasons-- https://master.php.net/note/delete/92301 Reject -- https://master.php.net/note/reject/92301 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158445) next »