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
PHP Articles
Page 33 of 81
PHP Resources
In PHP, Resource is a special data type that refers to any external resource. A resource variable acts as a reference to external source of data such as stream, file, database etc. PHP uses relevant functions to create these resources. For example, fopen() function opens a disk file and its reference is stored in a resource variable. PHP's Zend engine uses reference counting system. As a result, a resource with zero reference count is destroyed automatically by garbage collector. Hence, memory used by resource data type need not be freed manually. Common Resource Types Various types of ...
Read MorePHP Objects.
In PHP, Object is a compound data type (along with arrays). Values of more than one types can be stored together in a single variable. Object is an instance of either a built-in or user defined class. In addition to properties, class defines functionality associated with data. Primary (scalar) variables, arrays and other objects can be cast to object data type using casting operator. PHP provides stdClass as a generic empty class which is useful for adding properties dynamically and casting. Syntax To declare an object of a class we need to use new statement ? ...
Read MorePHP NULL
In PHP, a variable with no value is said to be of null data type. Such a variable has a value defined as NULL. A variable can be explicitly assigned NULL or its value can be set to null by using the unset() function. Syntax $var = NULL; It is possible to cast a variable of other type to null, although casting null to other type has been deprecated from PHP 7.2. In earlier versions, casting was done using (unset)$var syntax. Example Following example shows how to assign NULL to a variable ? ...
Read MorePHP Iterables
From PHP 7.1 onwards, PHP provides a pseudo-type called iterable that accepts any object implementing the Traversable interface, including arrays. This type declaration ensures parameters can be used with foreach loops or generator functions. Syntax A function can declare iterable as a parameter type to accept values usable in foreach statements. If the parameter doesn't support iteration, PHP throws a TypeError − function functionName(iterable $parameter): iterable { // Function body } Example with Array Parameter This example shows how to use iterable as a function parameter type ? ...
Read MorePHP Floating Point Data Type
In PHP, the float data type represents any number with a decimal point or fractional part. Float values can be written in standard decimal notation or scientific notation using e or E. The size and precision of floats depend on the platform, though precision up to 14 decimal digits is commonly supported. Syntax // Standard decimal notation $var = 5327.496; // Scientific notation (lowercase e) $var1 = 5.327496e3; // Scientific notation (uppercase E) $var2 = 5.327496E3; // Using underscore separator for readability (PHP 7.4+) $var3 = 5_327.496; For better readability, float ...
Read MorePHP Callbacks/Callables
Callbacks are functions or methods that can be called dynamically using their names or references. In PHP, any callable entity (functions, methods, closures) can be passed as a parameter and executed later using built-in functions like call_user_func(). Checking if Something is Callable The is_callable() function verifies if an identifier can be called as a function ? bool(true) bool(false) Using Built-in Functions as Callbacks Built-in PHP functions can be called using call_user_func() ? HELLO WORLD 5 User-Defined Function Callbacks Custom functions ...
Read MorePHP Tags
PHP tags are special markers that tell the PHP parser where PHP code begins and ends within a file. These tags allow you to embed PHP code within HTML documents, enabling server-side processing before the content is sent to the browser. Basic PHP Tags The standard PHP opening and closing tags are . All PHP statements must be written between these tags to be processed by the server. Syntax Example Hello World Short Echo Tags PHP provides a shorthand syntax ...
Read MorePHP Escaping From HTML
PHP allows you to seamlessly mix PHP code with HTML in a single file. When PHP encounters opening HTML block HTML block Every time the PHP parser encounters an opening tag, it starts executing PHP code until it reaches the closing tag. When PHP code contains conditional statements, the parser determines which blocks to execute or skip. Everything outside PHP tags is treated as HTML and processed by the browser. Basic Example The following example demonstrates PHP code embedded within HTML − ...
Read MorePHP 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 More