PHP

Last Updated on June 11, 2025 by বিডি কিক

What is PHP

  • Full form of PHP – Hypertext Preprocessor
  • Server scripting language, powerful tool/language for making dynamic websites

Note: The main difference between Scripting and Programming Language is – “Scripting language need interpreter, but programming language need compiler.

Why PHP

  • Popular, full free, and efficient
  • Flexible
  • Open source general-purpose scripting language
  • Specially suited for web development and can be embedded into HTML.
  • Best Part: PHP is that it is extremely simple for a newcomer,

What can do PHP

  • Server-side scripting: CGI features
  • Command line scripting
  • Writing desktop applications

History of PHP

  • First PHP created by Rasmus Ledorf at 1994 (Made by (CGI) binaries written in the C programming language)
  • Reason: Tracking visits to his online resume, so he named it Personal Home Page Tools, short form PHP tools

Environment Setup & Editor Setup for PHP

  • Xampp
  • Code Editor – Visual Studio Code
  • Web Browser – Google Chrome

PHP Syntax

Create a php file, a php file extension must be php.

// Opening and Closing PHP tag

<?php
   //php code
?>

// Short echo tag

<?=  ?>

Note 1: Short echo tag can be enable/disable by php.ini file
// Opening and Closing PHP tag

<?php
   //php code
?>

// Short echo tag

<?=  ?>

Note 1: Short echo tag can be enable/disable by php.ini file
// Opening and Closing PHP tag

<?php
   //php code
?>

// Short echo tag

<?=  ?>

Note 1: Short echo tag can be enable/disable by php.ini file
Note 2: If your PHP files contain only PHP code, it's preferable to skip the PHP closing tag

Statement, echo, print, PHP and HTML

Statement: A line of code.
echo: output string and variable (can be used with or without parentheses)
print: output string and variable (can be used with or without parentheses)

Note: echo is faster compare to print.

PHP and HTML

  • PHP and HTML code can use in same file, ensure your file is a php file.
  • Live

Variable and Constant

  • Variable: Variable is a value, data which can change.
  • Constant: Constant is also one type variable, but this value can’t be change while program is running.

Variable Name can be define by different way:
Camel Case: $myName
Pascal Case: $MyName
Snake Case: $my_name

Variable and Constant – Naming Convention

  • Must be start with $ sign
  • Must be start with Alphabet or Underscore
  • Name can contain alpha-numeric characters and underscores (A-z, 0-9, and _ )

Note: Variable name are Case Sensitive.

Magic Constant

Magic constant are some pre defined constant by PHP, it’s change dynamically his value based on where it’s using.

    // print the line no
    
    
    echo '__LINE__ This instruction line number ' . __LINE__ . "<br>";  



    // print the file directory including file name
    echo '__FILE__ This file directory  ' . __FILE__ . "<br>";  
   

     // print the directory
    echo '__DIR__ This file directory ' . __DIR__ . "<br>";  


    // print the function name

    function my_sujon(){
        echo '__FUNCTION__ This statement from function ' . __FUNCTION__ . "<br>";  
        
    }


    
    my_sujon();

Operators

Operator TypeOperators
Arithmetic OperatorsAddition (+)
Subtraction (-)
Multiplication ()
Division (/)
Modulus (%)
Exponentiation (**)
Assignment operators
Comparison operatorsEqual (==)
Identical (===)
Not equal (!=)
Not equal (<>)
Not identical (!==)
Greater than (>)
Less than (<)
Greater than or equal to (>=)
Less than or equal to (<=)
Spaceship (<=>)
Increment/Decrement operatorsPre-increment (++$i)
Post-increment ($i++)
Pre-decrement (–$x)
Post-decrement ($x–)
Logical operatorsAnd (and)
Or (or)
Xor (xor)
And (&&)
Or (||)
Not (!)
String operatorsConcatenation (.)
Concatenation assignment (.=)
Array operatorsUnion (.)
Equality (==)
Identity (===)
Inequality (!=)
Inequality (<>)
Non-identity (!==)
Conditional assignment operatorsTernary (?:)
Null coalescing (??)

PHP Data Types

There are mainly 8 datatypes in PHP.

  1. String
  2. Integer
  3. Float (floating point numbers – also called double)
  4. Boolean
  5. Array
  6. Object
  7. NULL
  8. Resource
Data TypesDescription
StringWhen a variable store character or text, it’s a String.
Example:
$x = “abc”;

Note: String can wrap with single quote or double quote.
IntegerInteger means the number, which can have a negative or positive value, but not a decimal point. Integer has a limit, it depends on the computer bit.
FloatFloat means the decimal point number.
BooleanBoolean use for conditional testing. True and False can be values of a boolean type variable. (Case Insensitive)
ArrayArray is one kind of date type, which can store multiple data at a time.
Object Object use for OOP
NULLNull mean where you have assign nothing, also you can assign null. (Special Type)
Resource
Spread the love

Leave a Comment