Programming Articles

Page 1043 of 2547

PHP program to find standard deviation of values within an array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 983 Views

Standard deviation measures how spread out values are from the average in a dataset. In PHP, you can calculate it by finding the mean, computing variances, and taking the square root of the average variance. Syntax The formula for standard deviation is ? Standard Deviation = sqrt(sum((value - mean)²) / count) Example Here's how to create a function to calculate standard deviation ? The standard deviation of elements in the array is 35.423156268181 How It Works The std_deviation() function works in the following steps ...

Read More

Redirection in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 7K+ Views

The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client). Syntax header($header_value, $replace_value, $http_response_code) Parameters header_value − The header string to be sent replace_value − Optional boolean that indicates whether to replace a previous similar header (default: true) http_response_code − Optional HTTP response code (default: 302 for redirects) Basic Redirection Example Here's how to redirect to another website − The exit statement is crucial ...

Read More

The internal working of the 'foreach' loop in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 287 Views

The 'foreach' loop in PHP helps in accessing key value pairs within an array. The 'foreach' loop works with arrays only, with the advantage that a loop counter wouldn't need to be initialized. In addition to this, no condition needs to be set that would be needed to exit out of the loop. The 'foreach' loop implicitly does this too. Basic Foreach Syntax The foreach loop has two syntax variations − foreach ($array as $value) { // Process each value } foreach ($array as $key => $value) { ...

Read More

How to delete an element from an array in PHP and re-index the array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

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 More

How to check if a string contains a specific sub string?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 791 Views

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 More

What is the significance of '^' in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 498 Views

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 More

What is the meaning and usage of '=&' assignment operator in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

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 More

PHP Predefined Mathematical Constants

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 262 Views

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 More

PHP tan() Function

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 225 Views

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 More

PHP srand() Function

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 408 Views

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 More
Showing 10421–10430 of 25,466 articles
Advertisements