Please help :D. I've googled for an hour and couldn't find anything to help !
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title> 2D Arrays </title>
- <style type="text/css">
- table {
- border-width: 1px 1px 1px 1px;
- border-style: outset outset outset outset;
- margin-left:auto; margin-right:auto;
- text-align: center;
- }
- tr {
- }
- td {
- border-style: solid solid solid solid;
- }
- td.blue {
- border-style: solid solid solid solid;
- background-color: #00CCFF;
- }
- td.orange {
- border-style: solid solid solid solid;
- background-color: #FFCC33;
- }
- </style>
- </head>
- <body>
- <?php
- /*
- Printing the entire array
- Retrieving all the keys of the array
- Retrieving all values of the array
- Iterating and displaying the array without a for loop
- Sorting the array in any manner you like
- Splicing 3 elements to the array in the middle
- */
- $num[0] = 5;
- $num[1] = 4;
- $num[2] = 3;
- $num[3] = 2;
- $num[4] = 1;
- $num[5] = 100;
- $asso["ACE"] = 1;
- $asso["TWO"] = 2;
- $asso["THREE"] = 3;
- $asso["FOUR"] = 4;
- $asso["FIVE"] = 5;
- $asso["SIX"] = 6;
- $keys = array_keys($num);
- $values = array_values($num);
- sort(&num, SORT_NUMERIC);
- ?>
- <table>
- <tr>
- <td class = "blue"> <b> Printing the entire array </b> </td>
- <td> <?php echo "$num[0]"; ?> </td>
- <td> <?php echo "$num[1]"; ?> </td>
- <td> <?php echo "$num[2]"; ?> </td>
- <td> <?php echo "$num[3]"; ?> </td>
- <td> <?php echo "$num[4]"; ?> </td>
- <td> <?php echo "$num[5]"; ?> </td>
- </tr>
- <tr>
- <td class = "blue"> <b> Retrieving all the keys of the array </b> </td>
- <td> <?php echo "$keys[0]"; ?> </td>
- <td> <?php echo "$keys[1]"; ?> </td>
- <td> <?php echo "$keys[2]"; ?> </td>
- <td> <?php echo "$keys[3]"; ?> </td>
- <td> <?php echo "$keys[4]"; ?> </td>
- <td> <?php echo "$keys[5]"; ?> </td>
- </tr>
- <tr>
- <td class = "blue"> <b> Retrieving all the values of the array </b> </td>
- <td> <?php echo "$values[0]"; ?> </td>
- <td> <?php echo "$values[1]"; ?> </td>
- <td> <?php echo "$values[2]"; ?> </td>
- <td> <?php echo "$values[3]"; ?> </td>
- <td> <?php echo "$values[4]"; ?> </td>
- <td> <?php echo "$values[5]"; ?> </td>
- </tr>
- <tr>
- <td class = "blue"> <b> Iterating and displaying the array without a for loop </b> </td>
- <td> <?php echo current($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- </tr>
- <?php
- sort(&num, SORT_NUMERIC);
- ?>
- <tr>
- <td class = "blue"> <b> Sorting the array in any manner you like </b> </td>
- <td> <?php echo reset($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- <td> <?php echo next($num); ?> </td>
- </tr>
- </table>
- </body>
- </html>