PHP_DS_Project/odkladiste.php
2024-09-08 12:45:11 +02:00

128 lines
2.6 KiB
PHP

<?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>";
};
}