note 113512 added to control-structures.foreach
| From: | saikurojv at gmail dot com | Date: | Wed, 23 Oct 2013 11:41:50 +0000 |
| Subject: | note 113512 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197302@lists.php.net to get a copy of this message | ||
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";
}
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 85.171.111.149
----
Manual Page -- http://php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/113512
Del: integrated -- https://master.php.net/note/delete/113512/integrated
Del: useless -- https://master.php.net/note/delete/113512/useless
Del: bad code -- https://master.php.net/note/delete/113512/bad+code
Del: spam -- https://master.php.net/note/delete/113512/spam
Del: non-english -- https://master.php.net/note/delete/113512/non-english
Del: in docs -- https://master.php.net/note/delete/113512/in+docs
Del: other reasons-- https://master.php.net/note/delete/113512
Reject -- https://master.php.net/note/reject/113512
Search -- https://master.php.net/manage/user-notes.php