2024-09-08 10:45:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Přepisování proměnných (statické a dynamické typování)
|
|
|
|
$name = "Lukáš";
|
|
|
|
$adult = true;
|
|
|
|
echo $name;
|
|
|
|
echo "<br>";
|
|
|
|
// Pravda, nepravda = true, false
|
|
|
|
$kolej = false;
|
|
|
|
$adult = false;
|
|
|
|
|
|
|
|
$is_logged = true;
|
|
|
|
$database_connection = false;
|
|
|
|
|
|
|
|
echo "Přihlášení uživatele: $is_logged";
|
|
|
|
echo "<br>";
|
|
|
|
echo "Napojení do databáze: $database_connection";
|
|
|
|
|
|
|
|
// Null
|
|
|
|
$kolej = null;
|
|
|
|
echo $kolej;
|
|
|
|
|
|
|
|
$kolej = "Nebelvír";
|
|
|
|
echo $kolej;
|
|
|
|
|
|
|
|
// Matematické operace
|
|
|
|
$students_2022 = 100;
|
|
|
|
$students_2023 = 124;
|
|
|
|
|
|
|
|
$results = $students_2022 - $students_2023 * 5;
|
|
|
|
$results2 = $students_2022 + $students_2023;
|
|
|
|
$results3 = $students_2022 * $students_2023 ;
|
|
|
|
$results4 = $students_2022 / $students_2023;
|
|
|
|
echo "Výsledek: $results";
|
|
|
|
echo "<br>";
|
|
|
|
echo "Výsledek: $results2";
|
|
|
|
echo "<br>";
|
|
|
|
echo "Výsledek: $results3";
|
|
|
|
echo "<br>";
|
|
|
|
echo "Výsledek: $results4";
|
|
|
|
|
|
|
|
// Spojování proměnných
|
|
|
|
$first_name = "Harry";
|
|
|
|
$second_name = "Potter";
|
|
|
|
$friend_first_name = "Ron";
|
|
|
|
|
|
|
|
echo $first_name . " " . $second_name;
|
|
|
|
echo "<br>";
|
|
|
|
echo $first_name. " a " .$friend_first_name;
|
|
|
|
|
|
|
|
// Type conversion
|
|
|
|
$year_price = "1500";
|
|
|
|
$year_caunt = "7";
|
|
|
|
|
|
|
|
$results_price = $year_price * $year_caunt;
|
|
|
|
|
|
|
|
echo $results_price;
|
|
|
|
echo "<br>";
|
|
|
|
var_dump($results_price);
|
|
|
|
echo "<br>";
|
|
|
|
var_dump($year_caunt);
|
|
|
|
|
|
|
|
// Negace
|
|
|
|
$database_connection1 = true;
|
|
|
|
var_dump(!$database_connection1);
|
|
|
|
|
|
|
|
// Pole (array)
|
|
|
|
|
|
|
|
$students = ["Harry", "Ron", "Hermiona"];
|
|
|
|
$students2 = [1 => "Harry", 65 => "Ron", "Hermiona"];
|
|
|
|
|
|
|
|
echo $students[1];
|
|
|
|
echo "<br>";
|
|
|
|
var_dump($students);
|
|
|
|
echo "<br>";
|
|
|
|
var_dump($students2);
|
|
|
|
|
|
|
|
// Asociatvní pole
|
|
|
|
|
|
|
|
$students3 = [
|
|
|
|
"first_name" => "Harry",
|
|
|
|
"second_name" => "Potter",
|
|
|
|
"college" => "Nebelvír",
|
|
|
|
"age" => 15
|
|
|
|
];
|
|
|
|
echo $students3["second_name"];
|
|
|
|
|
|
|
|
// Dvoudimenzionální pole (pole v poli)
|
|
|
|
$students4 = [
|
|
|
|
[
|
|
|
|
"first_name" => "Harry",
|
|
|
|
"second_name" => "Potter",
|
|
|
|
"age" => 15
|
|
|
|
],
|
|
|
|
["first_name" => "Hermiona",
|
|
|
|
"second_name" => "Grangerová",
|
|
|
|
"age" => 14
|
|
|
|
],
|
|
|
|
["first_name" => "Ron",
|
|
|
|
"second_name" => "Weasly",
|
|
|
|
"age" => 15],
|
|
|
|
];
|
|
|
|
var_dump($students4);
|
|
|
|
echo "<br>";
|
|
|
|
echo $students4[0]["first_name"];
|
|
|
|
echo "<br>";
|
|
|
|
echo $students4[2]["second_name"];
|
|
|
|
|
|
|
|
// Foreach cyklus
|
|
|
|
$students5 = ["Harry", "Ron", "Hermiona", "Malfoy"];
|
|
|
|
foreach ($students5 as $index => $one_student5) {
|
|
|
|
$index++;
|
|
|
|
echo $index.". " . $one_student5;
|
|
|
|
echo "<br>";
|
|
|
|
|
|
|
|
// Foreach cyklus
|
|
|
|
$students6 = [
|
|
|
|
"jmeno" => "Harry",
|
|
|
|
"prijmeni" => "Potter",
|
|
|
|
"kolej" => "Nebelvír",
|
|
|
|
"vek" => 15
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($students6 as $index1 => $one_information) {
|
|
|
|
echo $index1.": ".$one_information;
|
|
|
|
echo "<br>";
|
2024-09-08 13:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cyklus foreach - na práci s polem
|
|
|
|
// Cyklus for
|
|
|
|
for ($i = 1; $i <= 30; $i++) {
|
|
|
|
echo $i. " .Harry";
|
|
|
|
echo '<br>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cyklus foreach - na práci s polem
|
|
|
|
// Cyklus for - kolikrát se má cyklus provést
|
|
|
|
for($y = 1; $y <= 5; $y++) {
|
|
|
|
echo "<a href='./stranky/stranka$y.php'>Další stránka</a>";
|
|
|
|
echo "<br>";
|
|
|
|
};
|
|
|
|
|
|
|
|
// Cyklus foreach - na práci s polem
|
|
|
|
// Cyklus for - kolikrát se má cyklus provést
|
|
|
|
// Cyklus while - while cyklus znamená dokud - nevíme kolikrát (provádí se dokud platí podmínka)
|
|
|
|
$month = 1;
|
|
|
|
while ($month <=12){
|
|
|
|
echo $month;
|
|
|
|
echo "<br>";
|
|
|
|
$month = $month + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$test_questions = ["1. otázka", "2. otázka", "3. otázka", "4. otázka", "5. otázka"];
|
|
|
|
$maximum = 2;
|
|
|
|
$counter = 0;
|
|
|
|
|
|
|
|
while($counter < $maximum) {
|
|
|
|
echo $test_questions[$counter];
|
|
|
|
echo "<br>";
|
|
|
|
$counter++;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Podmínky
|
|
|
|
if (5 > 20) {
|
|
|
|
echo "Ano, je to pravda";
|
|
|
|
} else {
|
|
|
|
echo "Není to pravda";
|
2024-09-08 13:15:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//Podmínky a empty
|
|
|
|
$articles = [];
|
|
|
|
|
|
|
|
var_dump(empty($articles));
|
|
|
|
echo "<br>";
|
|
|
|
|
|
|
|
if (empty($articles)) {
|
|
|
|
echo "Neexistují žádné články";
|
|
|
|
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// VYpsání článků z databáze
|
|
|
|
echo "<br>";
|
2024-09-09 21:04:03 +00:00
|
|
|
echo 'Další kód na stránce';
|
|
|
|
|
|
|
|
// Podmínky a elseif
|
|
|
|
$hour =15;
|
|
|
|
$message = null;
|
|
|
|
|
|
|
|
if($hour< 9) {
|
|
|
|
$message = "Dobré ráno";
|
|
|
|
} elseif ($hour < 12) {
|
|
|
|
$message = "Dobré dopoledne";
|
|
|
|
} elseif ($hour == 12) {
|
|
|
|
$message = "Dobré poledne";
|
|
|
|
} elseif ($hour < 18) {
|
|
|
|
$message = "Dobré odpoledne";
|
|
|
|
} else {
|
|
|
|
$message = "Dobrý večer";
|
|
|
|
}
|
|
|
|
echo $message;
|
|
|
|
|
|
|
|
// Podmínky a logické operátory - and, or
|
|
|
|
|
|
|
|
$age = 25;
|
|
|
|
|
|
|
|
if($age >= 18 and $age < 65) {
|
|
|
|
echo "Dospělí není v důchodovém věku";
|
|
|
|
} elseif ($age < 18){
|
|
|
|
echo "Dospívající";
|
|
|
|
} else {
|
|
|
|
echo "Důchodce";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
and - a zároveň
|
|
|
|
true, true -> true
|
|
|
|
true, false -> false
|
|
|
|
false, true -> false
|
|
|
|
false, false -> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Podmínky a logické operátory - and, or
|
|
|
|
// 12345, 66778
|
|
|
|
|
|
|
|
$password = "12345";
|
|
|
|
|
|
|
|
if($password === "12345" or $password === "66778") {
|
|
|
|
echo "Dveře se otvírají, můžete jít dál";
|
|
|
|
} else {
|
|
|
|
echo "Neplatný kód. Zkuste to prosím znovu";
|
|
|
|
}
|
|
|
|
|
|
|
|
// or - nebo
|
|
|
|
// true, true -> true
|
|
|
|
// true, false -> true
|
|
|
|
// false, true -> true
|
|
|
|
// false, false -> false
|
|
|
|
|
|
|
|
// Switch statement
|
|
|
|
$day = "po";
|
|
|
|
|
|
|
|
switch ($day) {
|
|
|
|
case "po":
|
|
|
|
echo "Pondělí";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ut":
|
|
|
|
echo "Úterý";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "st":
|
|
|
|
echo "Středa";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ct":
|
|
|
|
echo "Čtvrtek";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "pa":
|
|
|
|
echo "Pátek";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "so":
|
|
|
|
echo "Sobota";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "ne":
|
|
|
|
echo "Neděle";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
echo "Neznámý den";
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|