Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
dvprog_07 [2015-01-23 15:24] Daniel Viström |
dvprog_07 [2019-09-26 10:52] Daniel Viström |
||
---|---|---|---|
Line 15: | Line 15: | ||
// Lägga in data i array | // Lägga in data i array | ||
// Skriva ut ett värde på en speciell position | // Skriva ut ett värde på en speciell position | ||
- | include(' | + | include ' |
- | echo '< | + | |
- | $names = array (' | + | $names = [' |
echo $names; | echo $names; | ||
- | echo '< | + | echo '< |
print_r($names); | print_r($names); | ||
- | echo $names[1] . '< | + | echo $names[1] . '< |
- | + | ||
- | $i=0; | + | |
- | while ($i < 3) { // Använd en loop för att gå igenom allt innehåll. | + | |
- | echo 'Namn ' . $i . ' är: ' . $names[$i] . '< | + | |
- | $i++; | + | |
- | } | + | |
- | $i=0; | + | // Använd en loop för att gå igenom allt innehåll i arrayen, t.ex. då det ska skrivas ut. |
+ | $i = 0; | ||
while ($i < count($names)) { // count() tar reda på hur många det finns i en array | while ($i < count($names)) { // count() tar reda på hur många det finns i en array | ||
- | echo 'Namn ' . $i . ' är: ' . $names[$i] . '< | + | echo 'Namn ' . $i . ' är: ' . $names[$i] . '< |
$i++; | $i++; | ||
} | } | ||
- | |||
- | |||
- | echo '< | ||
- | //$ages = array (34,23,45); | ||
- | $ages = array ( // Kan byta till andra nycklar än siffror. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ); | ||
- | print_r($ages); | ||
- | echo $ages[' | ||
$i=3; | $i=3; | ||
Line 62: | Line 45: | ||
print_r($arr2); | print_r($arr2); | ||
- | $arr3 = array ( // Kan innehålla flera olika saker. | + | echo '< |
+ | //$ages = array (34, | ||
+ | $ages = [ // Kan byta till andra nycklar än siffror. | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ]; | ||
+ | print_r($ages); | ||
+ | echo $ages[' | ||
+ | |||
+ | $arr3 = [ // Kan innehålla flera olika saker. | ||
' | ' | ||
' | ' | ||
3 => 56, | 3 => 56, | ||
- | ' | + | ' |
- | ); | + | ]; |
print_r($arr3); | print_r($arr3); | ||
echo $arr3[' | echo $arr3[' | ||
+ | include ' | ||
+ | </ | ||
+ | |||
+ | |||
+ | <php> | ||
+ | /* | ||
+ | echo '< | ||
echo '</ | echo '</ | ||
- | include(' | + | */ |
- | </code> | + | </php> |