User Tools

Site Tools


kurs:demo.php

Differences

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

Link to this comparison view

kurs:demo.php [2014/09/10 21:22]
kurs:demo.php [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +<​h1>​Hallo</​h1>​
 +<?php
  
 +# variablendeklaration
 +global $person;
 +$a = 2;  // a = 1
 +$b = 3;
 +//$a = '​Hallo';​
 +
 +// echo "<​h1>"​ . $a * $b . "</​h1>";​
 +
 +printf("<​h1>​%d</​h1>​\n",​ $a * $b);     # printf ist besser
 +
 +# array 
 +
 +$z[1] = '​a';​
 +$z[2] = '​b';​
 +$z[3] = '​c';​
 +
 +/*
 +$person['​Mark'​] ​     = 33;
 +$person['​Habib'​] ​    = 50;
 +$person['​Alexander'​] = 54;
 +*/
 +
 +$person = array('​Mark' ​     => 33,                ​
 +                '​Alexander'​ => 54,
 + '​Habib' ​    => 50,
 + );
 +
 +
 +foreach ($z as $i) { 
 +   ​printf("​Wert %s\n",​$i);​
 +   }
 +
 +asort($person);​ // sortiert nach dem Value
 +
 +print_array($z); ​  
 +print_array($person); ​  
 +
 +# casten
 +$i = (int) 8;
 +$f = (float) 8;
 +
 +# typgleichheit
 +if (!($i === $f)) {
 +   ​printf("​%s ist nicht gleich %s \n", $i, $f);
 +  }
 +
 +$name = '​m';​
 +$name .= '​h';​
 +
 +echo "​$name\n"; ​
 +
 +function print_array($a) {   
 +   ​static $c = 0;
 +   ​printf("​function called %d times \n", ++$c);
 +   ​foreach ($a as $key => $value) { 
 +     ​printf("​%s ist %s\n", $key, $value);
 +   }
 +} // end function ​  
 +   
 +   
 +/*
 +dies
 +ist 
 +ein 
 +mehrzeiler
 +*/
 +
 +?>
 +</​code>​
kurs/demo.php.txt ยท Last modified: 2014/09/10 21:22 (external edit)