Welcome to the PHP Fundamentals repository! This repository is designed to help you learn and practice the basics of PHP programming language.
🚀 #PHP #PhpFundamentals #PhpBasic #OpenSource
- PHP (Hypertext Preprocessor) is a server-side scripting language widely used for web development.
- Executed on the server, PHP generates dynamic content before sending it to the browser.
- PHP code is embedded within HTML.
- Start with
<?php
and end with?>
.
<?php
// PHP code here
?>
In the context of mathematics, computer science, and programming, a variable is a symbolic name or identifier associated with a value that may be changed during the execution of a program. Essentially, it is a storage location (typically in computer memory) paired with an associated symbolic name (an identifier), which contains some known or unknown quantity or information referred to as a "value."
- Prefix with
$
. - Case-sensitive.
- No need to declare data types.
$name = "John";
$age = 25;
- Strings, Integers, Floats, Booleans, Arrays, Objects, NULL.
- Arithmetic, Assignment, Comparison, Logical, Increment/Decrement.
$x = 10;
$y = 5;
$sum = $x + $y;
if
,else
,elseif
.
$grade = 85;
if ($grade >= 60) {
echo "Pass";
} else {
echo "Fail";
}
for
,while
,do-while
,foreach
.
for ($i = 0; $i < 5; $i++) {
echo $i;
}
- Reusable blocks of code.
- Defined using
function
.
function greet($name) {
echo "Hello, $name!";
}
- Ordered maps.
- Numerical and associative arrays.
$colors = array("Red", "Green", "Blue");
$info = array("name" => "John", "age" => 30);
- Reading and writing to files.
$file = fopen("example.txt", "r");
echo fread($file, filesize("example.txt"));
fclose($file);
- Using
mysqli
orPDO
for database interactions.
$conn = new mysqli("localhost", "username", "password", "database");
- Protect against SQL injection and XSS attacks.
- Use prepared statements for database queries.
$stmt = $conn->prepare("INSERT INTO table (column) VALUES (?)");
$stmt->bind_param("s", $value);
$stmt->execute();
These notes cover the basics of PHP, but there's much more to explore. PHP is versatile and widely used for web development, from simple scripts to complex applications.
For in-depth learning, refer to the official PHP Documentation and explore real-world projects. Happy coding!
This repository is licensed under the MIT License, allowing for widespread use and collaboration.
For any questions, feedback, or collaboration inquiries, feel free to reach out:
- Email: [email protected]
Feel free to customize the content as needed to better suit your repository and audience. Let me know if you need further assistance!