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
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to delete an element from an array in PHP and re-index the array?
In PHP, you can delete an element from an array using the unset() function. However, this creates gaps in the array indices. To re−index the array with consecutive numeric keys, use the array_values() function. Using unset() and array_values() The unset() function removes an element by its key, while array_values() returns a new array with consecutive numeric indices ? Original array: array(5) { [0]=> string(4) "this" [1]=> string(2) "is" [2]=> string(1) "a" [3]=> string(6) "sample" ...
Read MoreHow to check if a string contains a specific sub string?
To check if a string contains a specific substring in PHP, you can use functions like strpos(), str_contains() (PHP 8+), or substr_count(). The most common approach is using strpos() which returns the position of the first occurrence of a substring. Using strpos() The strpos() function returns the position of the substring or false if not found − The substring is present within the string. Using str_contains() (PHP 8+) A more straightforward method available in PHP 8 and later − Substring found! ...
Read MoreWhat is the significance of '^' in PHP?
The '^' is a bitwise XOR (exclusive OR) operator in PHP that performs bitwise operations on operands. For each bit position, it returns 1 if the bits are different and 0 if they are the same. When used with strings, it operates on the ASCII values of characters. How XOR Works The XOR operator compares each bit of the first operand with the corresponding bit of the second operand − If bits are different: returns 1 If bits are the same: returns 0 Example with Numbers Here's how XOR works with integer values ...
Read MoreWhat is the meaning and usage of '=&' assignment operator in PHP?
The =& operator in PHP creates a reference assignment, where two variables point to the same data location in memory instead of copying the value. This is known as "assignment by reference" and helps avoid data redundancy by making both variables share the same underlying data. Syntax The syntax for reference assignment is − Basic Example Here's how reference assignment works with simple variables − my_val1: 89 my_val2: 89 Reference vs Copy Assignment Let's compare reference assignment with regular copy assignment − ...
Read MorePHP Predefined Mathematical Constants
PHP provides a comprehensive set of predefined mathematical constants that are essential for mathematical calculations. These constants are globally available and provide precise values for common mathematical operations. Core Mathematical Constants The most commonly used mathematical constants include pi, Euler's number, and their derivatives ?
Read MorePHP tan() Function
The tan() function returns the tangent ratio of a given angle in radians. In trigonometry, tangent of an angle is defined as the ratio of lengths of opposite side and adjacent side. tan(x) = opposite/adjacent Tangent of an angle is also defined as the ratio of its sine and cosine: tan(x) = sin(x)/cos(x) If x = 45 degrees, tan(x) = 1, as in a right-angled triangle, opposite and adjacent sides are equal. This function returns a float value. Syntax tan ( float $arg ) : float Parameters ...
Read MorePHP srand() Function
The srand() function is used to seed the random number generator in PHP. Seeding initializes the random number generator with a specific starting value, ensuring reproducible or truly random sequences. While seeding is done automatically in modern PHP versions, manual seeding gives you control over randomization. Syntax srand([ int $seed ]) : void Parameters Parameter Description Required seed An integer to be used as seed. If not provided, a random number is used automatically Optional Return Value This function doesn't return any value (void). Examples ...
Read MorePHP sqrt() Function
The sqrt() function returns the square root of a positive float number. Since square root for negative numbers is not defined, it returns NAN (Not a Number). This is one of the most commonly used mathematical functions in PHP. This function always returns a floating point number. Syntax sqrt ( float $arg ) : float Parameters Parameter Description arg A number whose square root is to be obtained Return Values PHP sqrt() function returns the square root of the given arg number. For negative numbers, ...
Read MorePHP sin() Function
The sin() function returns the sine of a given angle in radians. In trigonometry, sine of an angle is defined as the ratio of the length of the opposite side to the hypotenuse in a right triangle. sin(x) = opposite/hypotenuse For example, if x = 90 degrees (π/2 radians), sin(x) = 1, as the opposite side equals the hypotenuse in this case. This function returns a float value. Syntax sin(float $arg): float Parameters Parameter Description arg A floating point value representing the angle in radians ...
Read MorePHP round() Function
The round() function proves useful in rounding any floating point number up to a desired precision level. Positive precision parameter causes the number to be rounded after decimal point, whereas with negative precision, rounding occurs before decimal point. Precision is 0 by default. For example, round(10.6) returns 11, round(10.2) returns 10. The function always returns a floating point number. Syntax round(float $value, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): float Parameters Parameter Description value A float number to be rounded precision Number of decimal digits to ...
Read More