Differences

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

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
dvprog_12 [2013-04-15 14:16]
Daniel Viström created
dvprog_12 [2017-09-01 14:54]
127.0.0.1 external edit
Line 1: Line 1:
 +====== Genomgång 9 - Funktioner (referenser och default) ======
  
 <code php> <code php>
 <?php <?php
  
-function thousands($tal = 1) {  // Defaultvärde kan anges.+// Defaultvärde kan anges för en parameter. 
 +// Det används om inget annat skickas till funktionen. 
 +function thousands($tal = 1) {
   return $tal*1000;   return $tal*1000;
 } }
Line 46: Line 48:
 include('head.php'); include('head.php');
 $tal1 = 18; $tal1 = 18;
-echo 'tal1: ' . $tal1 . '<br />'; +echo 'tal1: ' . $tal1 . '<br>'; 
-echo 'thousands($tal1): ' . thousands($tal1) . '<br />';  +echo 'thousands($tal1): ' . thousands($tal1) . '<br>';  
-echo 'thousands(): ' . thousands() . '<br />';+echo 'thousands(): ' . thousands() . '<br>';
  
-echo 'tal1: ' . $tal1 . '<br />';+echo 'tal1: ' . $tal1 . '<br>';
 backwards($tal1); backwards($tal1);
-echo 'tal1 efter backwards: ' . $tal1 . '<br />';+echo 'tal1 efter backwards: ' . $tal1 . '<br>';
  
 $arr1 = array(1,3,4); $arr1 = array(1,3,4);
 $arr2 = arrayadd($arr1,5); $arr2 = arrayadd($arr1,5);
 print_r($arr1); print_r($arr1);
-echo ' $arr1 <br />';+echo ' $arr1 <br>';
 print_r($arr2); print_r($arr2);
-echo ' $arr2 <br />';+echo ' $arr2 <br>';
  
 arrayadd2($arr1,10); arrayadd2($arr1,10);
 print_r($arr1); print_r($arr1);
-echo ' $arr1 <br />';+echo ' $arr1 <br>';
  
 include('foot.php'); include('foot.php');