PHP Syntax:
PHP( Hypertext Preprocessor ) is a server side scripting language used for web development. It has a syntax similar to C, Java and Perl.
To use proper PHP opening tag '<?php' and closing tag'?>' to enclose your PHP with HTML document.
Here's a brief overview of some common php syntax elements.
- Variable: Start with a dollar sign($) Example: $name="suji";
- Comments: single line command begin with '//' and multi line commands use '/* */'.
- Printing/output: To display content use 'echo' and ' print'.
- Strings: Enclosed in single (' ') or double (" ")quotes. Example: $message='Hellow';.
- Conditional statement : Use ' if', 'else' and 'elseif' on execute code based on conditional.
- Loop: Common loop are ' for', 'while' and 'foreach'.
- Function : Defined using function keyword followed by the function name Example: function add ($x $y) { retuen $x + $y }
- Array: Declared using array() or short syntax [] in recent various. Example: $numbers[1,2 3];.
- Superglobal: Pre- define variable accessible any where to the script. Example:$_GET, $_POSY, $_SESSION.