<?php
$string = 'string';
$number = 1;
?>
## ASSIGNING MULTIPLE VARIABLE IN PHP
$var1 = $var2 = $var3 = $var4 = "String";
$var1 = $var2 = $var3 = $var4 = 4;
$var1 = $var2 = $var3 = $var4 = {};
$var1 = $var2 = $var3 = $var4 = [];
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
<?php
# To declare variables in php, you should prefix the variable name with
# a dollar sign and assign it the value. For example:
$msg = 'Hello World';
$number = 10;
$decimal = 98.6;
$result = true;
# To print out variable names, you can directly enter the variable name
# inside of a print or echo statement. For example:
echo "Variables: $msg, $number, $decimal, $result"
?>
// just assign it some value to declare it
$var = 'some value';
$name = "Josh"; //$varname = value
## Regex:
## ^[a-zA-Z_x80-xff][a-zA-Z0-9_x80-xff]*$
// PHP validate variable name
$regex = '/^[a-zA-Z_x80-xff][a-zA-Z0-9_x80-xff]*$/i';
// Valid
preg_match($regex, '_aas', $matches);
[
"_aas",
]
// Valid
preg_match($regex, '_validVariable', $matches);
[
"_validVariable",
]
// Valid
preg_match($regex, 'oth3r_valid_variable', $matches);
[
"oth3r_valid_variable",
]
//Invalid
preg_match($regex, 'invalid Variable', $matches);
[]
//Invalid
preg_match($regex, '0th3r_invalid_vriable', $matches);
[]
//Invalid
preg_match($regex, '0th3r_invalid_variable', $matches);
[]
<?php
//this is for beginners //
$animal = "cow";
?>
<?php
//declaring a variable in php
$name = "Ahmed Issah";
$age = 23;
?>
$varName = "Hello, World";
<?php
/* In PHP, a variable starts with the $ sign,
followed by the name of the variable:
*/
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>