• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP Broken Down

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
Welcome to the "PHP Broken Down" tutorial, php is a very powerful scripting lanuage which can do many great things, not just display text on a page, before we build anything meaningful we must learn the core language as it is essential to understand or write complex server side applications or pages.

What we will this tutorial be covering?
The basics:
Code:
   variables, arrays, data types, functions, arguments, return types, pass by value, scope, comments, blocks, nesting
Arithmetic Operations
Code:
    Oder of Precedence, +, -, *, /, %, ++, --, post & prefix operators
Conditional Statements:
Code:
   if / elseif/ else, switch, short hand e.g. ( x ? true : false; )
Iterators (aka loops):
Code:
   do, while, for, foreach
Exception Handling
Code:
    try, catch, throw, finally
Logical & Bitwise Operators
Code:
    &&, ||, xor, or, and, not, !, ^, &, |, ~, <<, >>
Classes:
Code:
   members, methods, new, self, $this, static and none static classes, visibility modifiers & most importantly inheritance
Built-in Functions
Code:
   too many to list :p
 
Last edited:
PHP also known as but very rarely called, Hypertext Preprocessor; it is a general purpose scripting language which can be used to manipulate data on the server.

Once php has manipulated the data on the server it can then send that data to the browser to be displayed or sent elsewhere to be manipulated further and or even store the data in a file, in memory or in a database.

This is why when you view the source of a webpage that has a php extension (e.g. index.php) you don't see any php.

All PHP code is encapsulated (aka enclosed) inside of two php tags
Example:
Code:
<?php
   // all php goes inside here
?>
Comments:
You might be asking yourself what is these forward slashes ( // )?
This is known as a single line comment, everything from the two forward slashes til end of the line will be ignored by the server.

Not only does php have single line comments, but it also has multi-line comments everything contained within the opening ( /* ) and closing ( */ ) multi-line comment is ignored by the server.
Code:
<?php
/*
place your comments
inside
this multi-line
comment
*/
?>
Variables:
All php variable names must start with a dollar sign ($) and you may not or at least should not use any reserved words as a variable name.
Below is an example of how to declare a variable in php
Code:
<?php
$myVariable;
?>

Notice the that little thing ( ; ) at the end of the variable, this is called a semi-colon it lets php know we are done with this statement, to move on to the next bit of code if any, a semi-colon is like a period in a sentence ( . ) telling the reader this is the end of the sentence.

Reserved words in php
78JUEjU.png


Arrays:
Php also has another storage type called an array, an array can hold multiple values, more on this later.
Code:
<?php
$myArray = array();
?>
 
Last edited:
Back
Top