Variable Declaration
In PHP, variables are defined with the $ sign.
$variable = variable value;
- There are some rules for defining variables.
- Variables cannot start with a number.
- Turkish characters cannot be used.
- Whitespace cannot be used.
- It is case-sensitive.
A declaration like $variable_1 can be made, and any value can be assigned to the variable.
$add = (mysql_query("INSERT INTO TableName (Field1, Field2, ...) VALUES ('Value1', 'Value2', ...)");
When this variable is executed, it will add data to the database.
$write = "Alpay"; The value of the variable is Alpay. When we print this variable to the screen, it will display Alpay.
$write = "Alpay";
echo $write;
echo "My name is: ".$write;
This will output "My name is: Alpay" to the screen.
When printing variables, we do not use ' symbols. We use the . symbol to concatenate both normal text and variables simultaneously. . is a concatenation symbol.
echo 'My name is: '; echo $write;
This will also output the same result, but instead of using two echo commands, we concatenate the two values to be printed with the . symbol.
If - Else Structure
if (conditions you want to be met) {
code to be executed when the condition is met
}
elseif (checks this condition if the previous condition is not met) {
Code to be executed when the condition is met
}
else {code to be executed when the condition is not met}
Example:
A program that gives the incorrect warning if the value entered from the outside is 1.
$Alpay = "1";
if($Alpay == "1") {
echo 'The entered value is correct.';
}
else {
echo 'The entered value is incorrect.';
}
Türkçe: https://niyazi.net/tr/php-degisken-tanimlama-ve-if-else-yapisi
Muhammed Niyazi ALPAY - Cryptograph
Senior Software Developer & Senior Linux System Administrator
Meraklı
PHP MySQL MongoDB Python Linux Cyber Security
There are none comment