Ondřej Žára, @0ndras
$num = 123;
$str = 'hello ' . "world $num"; // hello world 123
$ahoj = "world" // Parse error: syntax error
define("KONSTANTA", 8);
$a = "b";
$$a = KONSTANTA;
echo $b; // 8
function plus($a, $b = 1) {
return $a + $b;
}
if ($a == "b") { ... }
for ($i=0; i<count($pole); $i++) { ... }
try { ... } catch ($e) { ... }
switch ($x) {
case $y:
break;
}
$pi = 3.14;
$foo = "bar";
function plus($a, $b) {
// $pi nevidime
global $foo;
// $foo vidime
return $a + $b;
}
$_GET
, $_POST
$_SERVER
, $_...
$GLOBALS
$pole = array("jablka", "hrušky", "červi");
count($pole); // 3
for ($i=0; $i<count($pole); $i++) { echo $pole[$i]; }
$pole["strom"] = "třešně"; // ???
count($pole); // 4
$pole = array("foo", "bar"=>"baz");
print_r($pole);
foreach ($pole as $value) { echo $value; }
foreach ($pole as $key => $value) {
echo $key;
echo $value;
}
error_reporting(E_ALL);
set_error_handler("jmeno_funkce"); // bude zavolana pri chybe
http://php.net/jmeno_funkce_kterou_hledam
echo ahoj;
// PHP Notice: Use of undefined constant ahoj - assumed 'ahoj'
if ($pole[$index]) { ... } // PHP Notice: Undefined index
if (array_key_exists($index, $pole)) { ... }
if (isset($pole[$index])) { ... }
include "knihovna.php"
include_once "knihovna.php"
<!-- soubor.html -->
<?php
$a = 13;
?>
...normalni html <znacky>...
<?php
echo $a;
?>