Php - Others

  • XAMPP
    • PHP development environment
    • Console Panel
    • C:\xampp\htdocs => Make projects inside this path
  • Basic
    • Operators
      • Arithmetic => +, -, /, *
      • Assignment => =, +=, -=, /=, *=
      • Comparison => ==, !=, >=, <=
      • Increment/Decrement => ++, --
      • Logical => &&, ||, xor, !
    • Data Types
      • String => $varName = "value"
      • Integer => $varName = N
      • Float => $varName = N.M
      • Boolean => $varName = true
      • Array => $varName = array("value1", "value2", "value3");
      • Object
    • Syntax
          <?php
              // Single-line Comment
              /* Multi-line Comment */
              define("varName", value); // Constant
              $varName = value; // Initialize a variable
              var_dump(varName) // Returns type of the variable
          ?>
      
  • Print
        <?php
            echo "Namaste Dunia!"; // Prints the string value given
            echo "<br>"; // Executes the HTML
            echo $varName; // Prints the value of the variable
            echo $varName[N]; // Prints element in an array
        ?>
    
  • Conditional Statements
        <?php
            if (condition1) {
                // Statements
            } else if (condition2) {
                // Statements
            } else {
                // Statements
            }
        ?>
    
  • Loops
        <?php
            for ($a = N1; $a < N2; $a++) {
                // Statements
            }
            foreach ($varName as $value) {
                // Statements
            }
            while (condition) {
                // Statements
            }
            do {
                // Statements
            } while (condition);
        ?>
    
  • Array
    • count($varName) => Returns total number of elements
  • String
    • $varName."value" => String concatenation
    • strlen($varName) => Returns length of string
    • str_word_count($varName) => Returns number of words in string
    • strrev($varName) => Returns reversed string
    • strpos($varName, "value") => Returns the position of the value in string
    • str_replace("value1", "value2", $varName) => Returns the string with replaced value
  • Function
        function varName(arguments) {
            // Statements
        }
        varName(parameters);
    
Share: