Forum Topic: php array
Home > Forums > Tutorials > php array (91 views - 3 replies) |
||
| 1 |
| Author | Topics: |
|
What we need to do is start off with creating our array.
<?php $array = array( ); ?> Now lets add some details to our array. <?php $array = array( \'red\' => \'Apple\' , \'green\' => \'Grapes\' , \'blue\' => \'Berries\' ); ?> Now if we want to list BOTH color AND fruit, we will echo the color AND fruit. For now lets replace the color wtih the fruit, then we will display both. <?php $array = array( \'red\' => \'Apple\' , \'green\' => \'Grapes\' , \'blue\' => \'Berries\' ); foreach ($array as $color => $fruit) { /* will search our array & switch the fruit with the color */ echo \"$fruit<br>\\n\"; /* will output the fruits listed in our array! */ } ?> Now lets display our colors and fruits. very simple just adding an extract variable to our loop. <?php $array = array( \'red\' => \'Apple\' , \'green\' => \'Grape\' , \'blue\' => \'Berries\' ); foreach ($array as $color => $fruit) { echo \"$color = $fruit<br>\\n\"; } ?> simple! Enjoy |
| Toon-Workshop |
| 1 |



























