Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
dvprog_07 [2019-09-26 11:04]
Daniel Viström
dvprog_07 [2019-09-26 11:27]
Daniel Viström
Line 21: Line 21:
 echo '<br><br>'; echo '<br><br>';
 print_r($names);  // Bra för att testa program, men inte det man vill få ut annars. print_r($names);  // Bra för att testa program, men inte det man vill få ut annars.
 +echo '<br>';
 echo $names[1] . '<br><br>'; // Andra namnet skrivs ut (index startar från 0). echo $names[1] . '<br><br>'; // Andra namnet skrivs ut (index startar från 0).
  
Line 29: Line 30:
   $i++;   $i++;
 } }
 +echo '<br>';
  
 $i=0; $i=0;
Line 46: Line 48:
  
 echo '<br><br>'; echo '<br><br>';
-//$ages = array (34,23,45);+//$ages = [34,23,45];
 $ages = [         // Kan byta till andra nycklar än siffror. $ages = [         // Kan byta till andra nycklar än siffror.
   'Astrid' => 34,        // Lättare att se om man delar upp på flera rader.   'Astrid' => 34,        // Lättare att se om man delar upp på flera rader.
Line 53: Line 55:
 ]; ];
 print_r($ages); print_r($ages);
-echo $ages['Birgitta'] . '<br><br>';+echo '<br>'$ages['Birgitta'] . '<br><br>';
  
 $arr3 = [     // Kan innehålla flera olika saker. $arr3 = [     // Kan innehålla flera olika saker.
Line 61: Line 63:
    'colors' => ['Red','Green','Yellow'  // Array innuti en array.    'colors' => ['Red','Green','Yellow'  // Array innuti en array.
 ]; ];
 +echo '<pre>';
 print_r($arr3); print_r($arr3);
 +echo '</pre><br>';
 +
 echo $arr3['colors'][2];  // Först yttre nyckeln, sedan inre nyckeln. echo $arr3['colors'][2];  // Först yttre nyckeln, sedan inre nyckeln.