note 113512 deleted from control-structures.foreach by googleguy

From: Date: Wed, 23 Oct 2013 14:31:01 +0000
Subject: note 113512 deleted from control-structures.foreach by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197306@lists.php.net to get a copy of this message
Note Submitter: saikurojv at gmail dot com ---- If you use list() to display a multidimensional array in a version older than php 5.5 it will display a syntax error like this: Parse error: syntax error, unexpected 'list' (T_LIST) Because he doesnt recognize list in foreach function. But if you try this : <?php $array = array( 86 => array(10 => 'Dog'), 62 => array(11 => 'Cat'), 92 => array(11 => 'Cat'), 93 => array(15 => 'Mouse'), 26 => array(26 => 'Butterfly') ); print_r($array); // it will done: Array ( [86] => Array ( [10] => Dog ) [62] => Array ( [11] => Cat ) [92] => Array ( [11] => Cat ) [93] => Array ( [15] => Mouse ) [26] => Array ( [26] => Butterfly ) ) ?> So to add multiple informations in the same array and show them, you have to use a foreach to display the array first, between using foreach in a foreach, just like this: <?php foreach($array as $key1 => $value1) { echo "key n°:".$key1."<br />"; foreach ($value1 as $key2=>$value2) { echo "key:".$key2.", Value: " . $value2 . "<br />n"; } } ?>

« previous php.notes (#197306) next »