Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
PHP Operator Precedence
Operator precedence in PHP determines the order in which operations are evaluated in expressions. Understanding precedence helps you write correct code and avoid unexpected results. For example, in 2+6/3, division happens first (resulting in 2+2=4) because the division operator / has higher precedence than addition +. How Precedence Works When operators have the same precedence level, associativity (left-to-right or right-to-left) determines the evaluation order. You can override precedence using parentheses to force specific operations to execute first − 14 20 PHP Operator Precedence Table The following table lists PHP ...
Read MorePHP Execution Operator
The execution operator in PHP uses backticks (``) to execute shell commands and return their output as a string. This operator provides a convenient way to run system commands directly from PHP code and is functionally equivalent to the shell_exec() function. Syntax The basic syntax involves wrapping the command in backticks ? $result = `command`; Example 1: Directory Listing This example executes a directory listing command and captures the output ? Volume in drive C is Windows 10 Volume Serial Number is 540D-CE99 Directory of C:\xampp\php 01/27/2016 ...
Read MorePHP Error Control Operator
In PHP, the @ symbol is defined as the Error Control Operator. When it is prefixed to any expression, any error encountered by PHP parser while executing it will be suppressed and the expression will be ignored. Example Without Error Control Operator Following code tries to open a non-existing file for read operation, but PHP parser reports warning − The output of the above code is − Hello World PHP Warning: fopen(nosuchfile.txt): failed to open stream: No such file or directory in /home/cg/root/1569997/main.php on line 2 Example With Error ...
Read MorePHP Expressions
Almost everything in a PHP script is an expression. Anything that has a value is an expression. In a typical assignment statement ($x=100), a literal value, a function or operands processed by operators is an expression − anything that appears to the right of assignment operator (=). Syntax $x = 100; // 100 is an expression $a = $b + $c; // $b + $c is an expression $c = add($a, $b); // add($a, $b) is an expression $val ...
Read MorePHP goto Statement
The goto statement in PHP allows you to transfer program control to a specific labeled location within your code. It's typically used within conditional statements like if, else, or switch constructs to control program flow. Syntax statement1; statement2; if (expression) goto label1; statement3; label1: statement4; After statement2, if the expression evaluates to true, program flow jumps to label1. If false, statement3 executes normally. The program then continues with normal execution flow. Example 1: Conditional Jump This example demonstrates jumping to a label based on whether a number is even ...
Read MorePHP Variable functions
Variable functions in PHP allow you to call a function dynamically by storing its name in a variable. When you append parentheses to a variable containing a function name, PHP executes that function. This feature is particularly useful for implementing callbacks, function tables, and dynamic function calls. Note: Variable functions cannot be used with language constructs like echo, include, require, etc. Use function wrappers as a workaround when needed. Basic Variable Function Here's a simple example where a variable stores a function name and calls it ? Hello World ...
Read MorePHP return Statement
The return statement in PHP is used to return control of program execution back to the environment from which it was called. Upon returning, execution continues with the statement following the function call. When a return statement occurs inside a function, execution of that function terminates immediately, passing control back to the calling code. The return statement can optionally include an expression, in which case the value of that expression is returned along with control. If a return statement is encountered in an included script, execution of that script ends immediately and control returns to the script that ...
Read MorePHP require Statement
The require statement in PHP includes and executes a specified file. Unlike the include statement, if the required file is not found, PHP produces a fatal error and terminates the script execution. Syntax require "filename.php"; // or require("filename.php"); How require Works PHP searches for the file in the current directory first, then in directories specified in the include_path setting of php.ini. If the file is not found, PHP emits an E_COMPILE_ERROR and halts execution. Example Here's a simple example showing how require includes a file ?
Read MorePHP include_once Statement
The include_once statement in PHP includes and evaluates a specified file only once during script execution. Unlike the regular include statement, include_once prevents the same file from being loaded multiple times, which helps avoid redefinition errors and improves performance. The include_once statement is commonly used for loading configuration files, libraries, or setting up global variables that should only be initialized once during application execution. Syntax include_once 'filename.php'; // or include_once('filename.php'); Basic Example Here's a simple demonstration of how include_once works ? Main script started This content is ...
Read MorePHP Unsetting References
In PHP, you can break the binding between a variable and its reference using the unset() function. The unset() function doesn't destroy the content but only decouples the variable from its reference, allowing it to be used independently. Using unset() Function The most common way to unset a reference is using the unset() function ? before unsetting: 10 10 after unsetting: 10 20 After unsetting, $b can be used as a normal variable without affecting $a. Using NULL Assignment References can also be removed by assigning the variable ...
Read More