PHP Articles

Page 3 of 81

How to display logged-in user information in PHP?

Dishebh Bhayana
Dishebh Bhayana
Updated on 15-Mar-2026 3K+ Views

In this article, we will learn how to display logged-in user information using PHP sessions. When building web applications with authentication, displaying user information on various pages provides a personalized experience for users. We can implement user authentication and display logged-in user information using PHP sessions along with HTML forms. Let's explore this with practical examples. Basic User Authentication System This example demonstrates a complete login system with user authentication and information display − Filename: login.php Login Page Login ...

Read More

Sort Array of Objects by Object Fields in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 4K+ Views

In PHP, you can sort an array of objects by their properties using several built-in functions. Each approach offers different advantages depending on your specific requirements and coding style preferences. Using usort() Function with a Custom Comparison Function The usort() function provides the most flexible approach for sorting objects by custom logic ? Bob - 25 Alice - 30 Charlie - 35 Using Anonymous Functions You can also use anonymous functions for more concise code ? Mouse - $25.5 Keyboard - $75 Laptop ...

Read More

Sort a Multidimensional Array by Date Element in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 6K+ Views

In PHP, you can sort a multidimensional array by a specific element, such as a date, using various approaches. Let's explore three different methods ? Using array_multisort() The array_multisort() function sorts multiple arrays or multidimensional arrays based on one or more columns ? Array ( [0] => Array ( [date] => 2023-05-15 [name] => Alice ...

Read More

Saving an Image from URL in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 11K+ Views

There are several ways to save an image from a URL in PHP. Here are three common methods − Using file_get_contents() and file_put_contents() Using cURL Using the GD library Using file_get_contents() and file_put_contents() Using file_get_contents() and file_put_contents() is a straightforward method to save an image from a URL in PHP ? In this code snippet, file_get_contents() retrieves the contents of the image file from the specified URL. The image data is then stored in the $image variable. Next, file_put_contents() saves ...

Read More

Refresh a Page Using PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 5K+ Views

In PHP, you can refresh a page using the header() function to send HTTP headers to the browser. This is useful for creating auto-refreshing pages or redirecting users after form submissions. Using header() Function The header() function sends HTTP headers to the browser. To refresh a page, you use the "Refresh" header with a specified delay time. Syntax header(string $header, bool $replace = true, int $http_response_code = 0): void Parameters $header − The header string to send (e.g., "Refresh: 5") $replace − Whether to replace previous similar headers (default: true) $http_response_code ...

Read More

PHP Program to Find the Number Occurring Odd Number of Times

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 287 Views

Finding a number that occurs an odd number of times in an array is a common programming problem. In PHP, this can be solved using different approaches like counting, hashing, or bitwise XOR operations. Problem Explanation Given an array where all numbers appear an even number of times except one, we need to find that single number which appears an odd number of times. For example, in the array [2, 3, 4, 3, 1, 4, 2, 1, 1], the number 1 appears 3 times (odd), while all other numbers appear an even number of times. Method ...

Read More

PHP Program to find the Closest Pair from Two Sorted Arrays

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 199 Views

Given two sorted arrays and a number x, we need to find a pair (one element from each array) whose sum is closest to x. This is a classic two-pointer problem that can be solved efficiently. Problem Statement Find a pair from two sorted arrays such that the sum of the pair is closest to a given target value x. Input: ar1 = [1, 3, 5, 7, 9]; ar2 = [2, 4, 6, 8, 10]; x = 12; Output: The closest pair is [1, 10] because 1+10=11 which is closest to 12 ...

Read More

PHP program to Fetch Data from Localhost Server Database using XAMPP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 1K+ Views

To fetch data from a localhost server database using XAMPP, you need to set up a local web server environment and create a PHP script that connects to your MySQL database. This tutorial will guide you through the complete process. Prerequisites: Install XAMPP from https://www.apachefriends.org/download.html before proceeding. Setting Up XAMPP Server Step 1: Start the XAMPP Server Launch the XAMPP control panel Start the Apache and MySQL services by clicking "Start" next to each service Step 2: Access phpMyAdmin ...

Read More

PHP Program to Count Trailing Zeroes in Factorial of a Number

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 346 Views

The factorial of a non-negative integer, denoted by the symbol "!", is the product of all positive integers less than or equal to that number. In other words, the factorial of a number is obtained by multiplying that number by all the positive integers below it. For example, the factorial of 5 is calculated as: 5! = 5 x 4 x 3 x 2 x 1 = 120 Similarly, the factorial of 0 is defined to be 1: 0! = 1 What are Trailing Zeroes? In the factorial of a number, trailing zeroes refer ...

Read More

PHP Program to Count set Bits in an Integer

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 439 Views

In PHP, counting set bits (1s) in an integer's binary representation is a common programming task. A set bit refers to a binary digit that has the value 1, while a clear bit has the value 0. For example, the number 12 in binary is 1100, which has 2 set bits. What is Binary Code? Binary code is a system of representing information using a base-2 numeral system. It uses only two digits, 0 and 1, to represent all values. Each digit in binary code is called a bit (short for binary digit). In binary code, each ...

Read More
Showing 21–30 of 802 articles
« Prev 1 2 3 4 5 81 Next »
Advertisements