note 81682 added to control-structures.foreach

From: Date: Sun, 09 Mar 2008 18:40:41 +0000
Subject: note 81682 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-136876@lists.php.net to get a copy of this message
Even if an array has only one value, it is still an array and foreach will run it. <?php $arr[] = "I'm an array."; if(is_array($arr)) { foreach($arr as $val) { echo $val; } } ?> The above code outputs: I'm an array. ---- Server IP: 209.41.74.194 Probable Submitter: 71.82.169.119 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/81682 Del: integrated -- https://master.php.net/note/delete/81682/integrated Del: useless -- https://master.php.net/note/delete/81682/useless Del: bad code -- https://master.php.net/note/delete/81682/bad+code Del: spam -- https://master.php.net/note/delete/81682/spam Del: non-english -- https://master.php.net/note/delete/81682/non-english Del: in docs -- https://master.php.net/note/delete/81682/in+docs Del: other reasons-- https://master.php.net/note/delete/81682 Reject -- https://master.php.net/note/reject/81682 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136876) next »