Req #60684 [NEW]: Add 'last' & 'first' blocks next to 'foreach' block

From: Date: Sun, 08 Jan 2012 06:41:49 +0000
Subject: Req #60684 [NEW]: Add 'last' & 'first' blocks next to 'foreach' block
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166288@lists.php.net to get a copy of this message
From: Operating system: All PHP version: 5.4.0RC5 Package: Arrays related Bug Type: Feature/Change Request Bug description:Add 'last' & 'first' blocks next to 'foreach' block Description: ------------ There are a lot of situations that we want our foreach loop act different for first and/or last item. It will be so easy if php add these to concepts as blocks next to foreach. Compiler will run 'first' block for first item, and 'last' block for last item, and normal 'foreach' block for anything in between. The only special case is when array has only one item, in this situation only 'first' block will act. See example at test script. Test script: --------------- foreach($array as $key => $value) { $str .= $key . ' = "'.$value.'",'; } first { $str .= '(' . $key . ' = "'.$value.'",'; } last { $str .= $key . ' = "'.$value.'")'; } -- Edit bug report at https://bugs.php.net/bug.php?id=60684&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60684&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60684&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60684&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60684&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60684&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60684&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60684&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60684&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60684&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60684&r=support Expected behavior: https://bugs.php.net/fix.php?id=60684&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60684&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60684&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60684&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60684&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60684&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60684&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60684&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60684&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60684&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60684&r=mysqlcfg

« previous php.bugs (#166288) next »