• array_key_exists()
$data = ['username' => 'Ashish', 'bio' => null];

// array_key_exists returns true because the key 'bio' is present
var_dump(array_key_exists('bio', $data)); // Output: bool(true)
  • var_dump()
$user = ["id" => 1, "active" => true];
var_dump($user);
/* Output:
array(2) {
  ["id"]=> int(1)
  ["active"]=> bool(true)
}
*/
  • array_push($stack, "Apple", "Raspberry");: Adds to the end

  • array_unshift(): Adds to the start

  • $result = array_merge($defaults, $userSettings) : merge the arrays

  • Function Declaration

function functionName() { }
$functionName = function() { };
function functionName ($arg1, $arg2) { }
  • echo: Does not have a return value
  • print: Always returns the integer 1
echo "This ", "is ", "multiple ", "parameters."; // accepts multiple params
$result = print "Hello"; // $result is now
  • include: If the file is missing, it generates a Warning (E_WARNING). The script will continue to execute the remaining code.
  • require: If the file is missing, it generates a Fatal Error (E_COMPILE_ERROR). The script will stop immediately.
  • isset()
$a = "test";
if (isset($a)) {
    echo "var set!";
}
  • $_SERVER: Contains information about headers, paths, and script locations.

  • $_POST: Used to collect data submitted via an HTML form with the method="post".

  • $_COOKIE: Used to retrieve values from HTTP cookies.

  • CSP (Content Security Policy) is an added layer of security used by web developers to detect and mitigate certain types of attacks, including Cross-Site Scripting (XSS) and Clickjacking.

  • Xdebug performs Server-side debugging and profiling in PHP.

  • The primary role of fopen() is to open a file or a URL and return a file pointer resource (often called a “handle”). This resource is then used as a reference by other functions like fread(), fwrite(), and fclose() to perform specific operations on that file.

  • Superglobals are always available in all scopes. echo "Hello, " . $_GET['user'];

  • error_log() is used for background logging. Default System Log: sends the message to the PHP error log defined in your php.ini file.

  • file_get_contents() Reads everything into a string.

  • debug_backtrace() function is a powerful tool used to generate a PHP backtrace. It provides a detailed “history” of the function calls that led to the exact point where the function was triggered.

function level3() {
    print_r(debug_backtrace());
}

function level2() {
    level3();
}

function level1() {
    level2();
}

level1();
  • mkdir() is used to create directory in PHP.
  • mysqli_real_escape_string() function creates a legal SQL string that can be used in an SQL statement. It takes a string and prepends backslashes to characters that could otherwise be misinterpreted by the MySQL database (such as single quotes, double quotes, and backslashes).
  • The mysqli_connect() function is the primary way to open a new connection to a MySQL database server using the MySQL Improved (mysqli) extension in PHP.
$connection = mysqli_connect(host, username, password, dbname, port, socket);
  • In PHP, a try-catch structure allows you to “try” a piece of code that might throw an error (an Exception). If an error occurs, the code inside the catch block is executed to handle it.
  • Visibility is strictly defined by these three keywords:
    1. public: The property or method can be accessed from anywhere (inside the class, by child classes, and from external code).
    2. protected: The property or method can only be accessed within the class itself and by child classes (inheritance).
    3. private: The property or method can only be accessed within the specific class that defined it.
  • Parameterized queries work by separating the SQL logic from the user data.
    1. Preparation: You send a query “template” to the database with placeholders (like ? or :name) instead of actual values.
    2. Binding: You send the user data separately.
    3. Execution: The database engine treats the data strictly as values and never as part of the executable code. Even if a hacker inputs a malicious command (like ' OR 1=1), the database simply looks for a user whose name is literally that string.
  • The htmlentities() function takes a string and converts all applicable characters into HTML entities. For example, it turns a < into &lt; and a > into &gt;
  • rmdir() function is used to remove directory
  • set_exception_handler() Sets a user-defined function to handle all uncaught exceptions.
function myGlobalExceptionHandler($exception) {
    // This runs for any exception NOT inside a try-catch
    error_log("Uncaught Exception: " . $exception->getMessage());
    echo "Something went wrong. Our team has been notified.";
}

// Register the handler
set_exception_handler('myGlobalExceptionHandler');

// Throw an exception outside of a try-catch
throw new Exception("Critical Database Failure!");