|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-09-21 14:46 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 18:00:01 2025 UTC |
Description: ------------ Could it be possible to have a new structure instruction to "foreach" ? I know that it possible to write with existing instructions but it could be usefull to have this one. It could easily replace some code block like "if(){try{foreach{}catch{}}}else{}" and provide more efficient and "bug disable" code... See the code, it's only a purpose. Reproduce code: --------------- $ar = array(0=>"one", 1=>"two"); foreach($ar as $ix $v) { catch begin { print "<table>"; print "<caption>My array have ".count($ar)." elements</caption>"; print "<tr><th>MyH1</th><th>...</th></tr>"; } catch end { print "</table>"; } catch each { print "<tr><th>$ix</th><th>$v</th></tr>"; } catch null { print "oups! my array is empty"; } catch exception $ex { print "oups! my code is so ugly that it done an error exception."; } } Expected result: ---------------- <table> <caption>My array have 2 elements</caption> <tr><th>MyH1</th><th>...</th></tr> <tr><th>0</th><th>one</th></tr> <tr><th>1</th><th>two</th></tr> </table> Actual result: -------------- oups! this instruction do not exists.