Please enable JavaScript.
Coggle requires JavaScript to display documents.
PHP (PHP (Basics (Variables, functions (Expressions & Operators (For…
PHP
PHP
Basics
-
$x = array("Daniel", "Hoang", "Jonny");
$x[0];
-
Append elements:
$names = array();
array_push($names, "Hoang");
array_push($names, 12, 33);
-
Associative Array:
$person = array("name"=>"Hoang", "age" => 25);
$person["email"] = "....";
"Key" can be a Number:
$department = array (1 => 'Accounts', 2 => 'Economics'');
echo $department[1];
-
Variables, functions
-
-
function multiply($x, $y) {
return $x + $y;
}
...
Call: multiple(2,3);
-
-
Installations
1.Download XAMPP, install.
2.Open XAMPP, start MySQL, Apache, open Config
3.Open httpd.conf, search DocumentRoot, change to Code Folder
Option1
Click Apache, Config, open httpd.conf
-
Save httpd.conf, restart Apache
Option2:
Start server using PHP(open in terminal):
C:\xampp\php\php.exe -S localhost:82 -t D:\abc\
82 = Port(82, 83, ...)
D:\abc = your code folder
form
Validate:
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
//Invalid email address
}
Perform Regex:
if(preg_match_all('/Hoang/', $input_string, $array_result)) {...}
Replace using Regex:
$output_string = preg_replace('/Hoang/', 'John', $input_text);
//Replace 'Hoang' by 'John'
$result = preg_match('/Hoang/', $input_string);
//1 or 0
-
/D.*/ => Ex: Daniel, Danish, Duck,...
-
-
/D{2, }/ => Eg: DD, DDD, DDDD,...
-
-
-
-