PHP

PHP Language Structure

Get Started. It's Free
or sign up with your email address
Rocket clouds
PHP by Mind Map: PHP

1. Data Types

1.1. String

1.1.1. $x = "Hello world!";

1.1.2. Functions

1.1.2.1. strlen

1.1.2.1.1. Length of a String

1.1.2.2. str_word_count

1.1.2.2.1. Count the number of words in a string

1.1.2.3. strrev

1.1.2.3.1. Reverse a string

1.1.2.4. strpos

1.1.2.4.1. Search For a Specific Text Within a String

1.1.2.5. str_replace

1.1.2.5.1. Replace Text Within a String

1.2. Integer

1.2.1. $x = 5985;

1.3. Float

1.3.1. $x = 10.365;

1.4. Boolean

1.4.1. $x = true;

1.5. Array

1.5.1. $cars = array("Volvo","BMW","Toyota");

1.5.2. Functions

1.5.2.1. sort()

1.5.2.1.1. sort arrays in ascending order

1.5.2.2. rsort()

1.5.2.2.1. sort arrays in descending order

1.5.2.3. asort()

1.5.2.3.1. sort associative arrays in ascending order, according to the value

1.5.2.4. arsort()

1.5.2.4.1. sort associative arrays in descending order, according to the value

1.5.2.5. array_keys

1.5.2.5.1. Return all the keys or a subset of the keys of an array

1.5.2.6. in_array

1.5.2.6.1. Checks if a value exists in an array

1.6. Associative Array

1.6.1. $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

1.7. Object

1.7.1. class Car { function Car() { $this->model = "VW"; } } // create an object $herbie = new Car();

1.8. NULL

1.8.1. $x = "Hello world!"; $x = null;

1.9. Resource

1.10. Constants

1.10.1. define(name, value, case-insensitive)

1.10.1.1. define("GREETING", "Welcome to W3Schools.com!"); echo GREETING;

2. Functions

2.1. User Defined Functions

2.1.1. function functionName() { code to be executed; }

2.2. Function Arguments

2.2.1. function familyName($fname, $year) { echo "$fname Refsnes. Born in $year <br>"; }

2.3. Function Default Argument Value

2.3.1. function setHeight($minheight = 50) { echo "The height is : $minheight <br>"; }

2.3.2. setHeight(350);

2.3.3. setHeight();

2.4. Returning Values

2.4.1. function sum($x, $y) { $z = $x + $y; return $z; }

3. Forms

3.1. Handling

3.1.1. $_POST

3.1.1.1. echo $_POST["name"];

3.1.2. $_GET

3.1.2.1. echo $_GET["name"];

3.2. Validation

3.2.1. FILTER_VALIDATE

3.2.1.1. FILTER_VALIDATE_EMAIL

3.2.1.2. FILTER_VALIDATE_URL

3.2.1.3. FILTER_VALIDATE_PHONE

4. Operators

4.1. Arithmetic

4.1.1. +

4.1.1.1. Sum of $x and $y

4.1.2. -

4.1.2.1. Difference of $x and $y

4.1.3. *

4.1.3.1. Product of $x and $y

4.1.4. /

4.1.4.1. Quotient of $x and $y

4.1.5. %

4.1.5.1. Remainder of $x divided by $y

4.1.6. **

4.1.6.1. Result of raising $x to the $y'th power (Introduced in PHP 5.6)

4.2. Assignment

4.2.1. x = y

4.2.1.1. The left operand gets set to the value of the expression on the right

4.2.2. x += y

4.2.2.1. Addition

4.2.3. x -= y

4.2.3.1. Subtraction

4.2.4. x *= y

4.2.4.1. Multiplication

4.2.5. x /= y

4.2.5.1. Division

4.2.6. x %= y

4.2.6.1. Modulus

4.3. Comparison

4.3.1. ==

4.3.1.1. Returns true if $x is equal to $y

4.3.2. ===

4.3.2.1. Returns true if $x is equal to $y, and they are of the same type

4.3.3. !=

4.3.3.1. Returns true if $x is not equal to $y

4.3.4. <>

4.3.4.1. Returns true if $x is not equal to $y

4.3.5. !==

4.3.5.1. Returns true if $x is not equal to $y, or they are not of the same type

4.3.6. >

4.3.6.1. Returns true if $x is greater than $y

4.3.7. <

4.3.7.1. Returns true if $x is less than $y

4.3.8. >=

4.3.8.1. Returns true if $x is greater than or equal to $y

4.3.9. <=

4.3.9.1. Returns true if $x is less than or equal to $y

4.4. Increment / Decrement

4.4.1. ++$x

4.4.1.1. Increments $x by one, then returns $x

4.4.2. $x++

4.4.2.1. Returns $x, then increments $x by one

4.4.3. --$x

4.4.3.1. Decrements $x by one, then returns $x

4.4.4. $x--

4.4.4.1. Returns $x, then decrements $x by one

4.5. Logical

4.5.1. and

4.5.1.1. True if both $x and $y are true

4.5.2. or

4.5.2.1. True if either $x or $y is true

4.5.3. xor

4.5.3.1. True if either $x or $y is true, but not both

4.5.4. &&

4.5.4.1. True if both $x and $y are true

4.5.5. ||

4.5.5.1. True if either $x or $y is true

4.5.6. !

4.5.6.1. True if $x is not true

4.6. String

4.6.1. .

4.6.1.1. Concatenation of $txt1 and $txt2

4.6.2. .=

4.6.2.1. Appends $txt2 to $txt1

4.7. Array

4.7.1. +

4.7.1.1. Union of $x and $y

4.7.2. ==

4.7.2.1. Returns true if $x and $y have the same key/value pairs

4.7.3. ===

4.7.3.1. Returns true if $x and $y have the same key/value pairs in the same order and of the same types

4.7.4. !=

4.7.4.1. Returns true if $x is not equal to $y

4.7.5. <>

4.7.5.1. Returns true if $x is not equal to $y

4.7.6. !==

4.7.6.1. Returns true if $x is not identical to $y

5. Loops

5.1. for

5.1.1. for (init counter; test counter; increment counter) { code to be executed; }

5.2. foreach

5.2.1. foreach ($array as $value) { code to be executed; }

5.3. while

5.3.1. while (condition is true) { code to be executed; }

5.4. do...while

5.4.1. do { code to be executed; } while (condition is true);

6. Files

6.1. readfile($fileName)

6.1.1. AJAX = Asynchronous JavaScript and XML CSS = Cascading Style Sheets HTML = Hyper Text Markup Language PHP = PHP Hypertext Preprocessor SQL = Structured Query Language SVG = Scalable Vector Graphics XML = EXtensible Markup Language

6.2. fopen()

6.2.1. Open file

6.3. fread()

6.3.1. Read file

6.4. fclose()

6.4.1. Close file

6.5. fileModes

6.5.1. r

6.5.1.1. Open a file for read only. File pointer starts at the beginning of the file

6.5.2. w

6.5.2.1. Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file

6.5.3. a

6.5.3.1. Open a file for write only. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist

6.5.4. x

6.5.4.1. Creates a new file for write only. Returns FALSE and an error if file already exists

6.5.5. r+

6.5.5.1. Open a file for read/write. File pointer starts at the beginning of the file

6.5.6. w+

6.5.6.1. Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file

6.5.7. a+

6.5.7.1. Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist

6.5.8. x+

6.5.8.1. Creates a new file for read/write. Returns FALSE and an error if file already exists

7. Databases

7.1. MySQL

7.1.1. Queries

7.1.1.1. SELECT

7.1.1.1.1. SELECT column_name(s) FROM table_name

7.1.1.2. DELETE

7.1.1.2.1. DELETE FROM table_name WHERE some_column = some_value

7.1.1.3. UPDATE

7.1.1.3.1. UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value

7.1.1.4. INSERT_INTO

7.1.1.4.1. INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)

7.2. Connection

7.2.1. MySQLi

7.2.1.1. $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully";

7.2.2. PDO

7.2.2.1. $servername = "localhost"; $username = "username"; $password = "password"; try { $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); }

7.3. PostgreSQL

7.4. MongoDB

7.5. others ...

8. Conditionals

8.1. if...else...elseif

8.1.1. if (condition) { code to be executed if condition is true; }

8.1.2. if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if this condition is true; } else { code to be executed if all conditions are false; }

8.2. switch

8.2.1. switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; ... default: code to be executed if n is different from all labels; }