PHP Articles

Page 4 of 81

PHP Program to Count Page Views

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

In PHP, counting page views is a common requirement for tracking user engagement and website analytics. This can be achieved using sessions to maintain a counter that persists across multiple page visits for each user session. What is Session? In PHP, a session is a way to store and persist data across multiple requests or page views for a specific user. When a user visits a website, a unique session ID is assigned to them, typically stored as a cookie on the user's browser. This session ID is used to associate subsequent requests from the same user with ...

Read More

PHP Program to Count Number of Binary Strings without Consecutive 1’s

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

In PHP, counting binary strings without consecutive 1's is a classic dynamic programming problem. A binary string contains only 0's and 1's, and we need to count valid strings where no two 1's appear next to each other. Understanding the Problem Let's analyze binary strings of length 3 to understand the pattern − All possible binary strings of length 3: 000, 001, 010, 011, 100, 101, 110, 111 Valid strings (without consecutive 1's): 000, 001, 010, 100 Invalid strings (with consecutive 1's): 011, 110, 111 So for length 3, we have 5 valid binary strings ...

Read More

PHP Program to check for Anagram

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

PHP (Hypertext Preprocessor) is a widely used server-side scripting language for web development. In PHP, you can check if two strings are anagrams by comparing their character frequencies using built-in functions. What is an Anagram? Anagrams are words or phrases formed by rearranging the letters of another word or phrase. In an anagram, all the original letters must be used exactly once, with no additional or missing letters. For example, "listen" and "silent" are anagrams because they use the same letters rearranged in different order. Using count_chars() Function The count_chars() function is a built-in PHP ...

Read More

PHP Program for Subset Sum Problem

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

The Subset Sum Problem is a classic problem in computer science and dynamic programming. Given a set of positive integers and a target sum, the task is to determine whether there exists a subset of the given set whose elements add up to the target sum. Using Recursive Solution The recursive approach explores all possible combinations by either including or excluding each element ? Found a subset with the given sum No subset with the given sum. In this example, the set is [1, 7, 4, 9, 2]. For sum ...

Read More

PHP Program for Rabin-Karp Algorithm for Pattern Searching

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

The Rabin-Karp algorithm is a string pattern matching algorithm that efficiently searches for occurrences of a pattern within a larger text. It was developed by Michael O. Rabin and Richard M. Karp in 1987. The algorithm utilizes a hashing technique to compare the hash values of the pattern and substrings of the text. It works as follows: Calculate the hash value of the pattern and the first window of the text. Slide the pattern over the text one position at a time and compare the hash values. If ...

Read More

PHP Program for Naive Algorithm for Pattern Searching

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

PHP (Hypertext Preprocessor) is a widely used server-side scripting language for web development. The Naive algorithm, also known as the Brute Force algorithm, is a simple pattern searching technique that finds occurrences of a pattern within a text by comparing characters one by one. What is Naive Algorithm? The Naive algorithm is called "naive" because it doesn't employ sophisticated data structures or advanced techniques. It works by iterating through the text and comparing each character with the corresponding character in the pattern. If a mismatch occurs, it moves to the next position in the text and starts the ...

Read More

PHP Program for Minimum Number of Jumps to Reach End

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

This problem involves finding the minimum number of jumps required to reach the end of an array, where each element represents the maximum number of steps you can jump from that position. Method 1: Naive Recursive Approach The naive recursive approach explores all possible paths from each position and chooses the minimum number of jumps − Minimum number of jumps required to reach the end: 3 Method 2: Dynamic Programming Dynamic programming optimizes the solution by storing results of subproblems to avoid redundant calculations − ...

Read More

PHP Program for Median of two Sorted Arrays of Same Size

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

The median is a value that separates the higher half from the lower half of a data set. When finding the median of two sorted arrays of the same size, we need to merge them conceptually and find the middle elements. This can be done efficiently using a merge-based approach without actually creating a new merged array. Algorithm Approach The solution uses two pointers to traverse both arrays simultaneously, keeping track of the two middle elements needed to calculate the median. Since we have 2n total elements, the median will be the average of elements at positions n-1 ...

Read More

PHP Program for Largest Sum Contiguous Subarray

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

The Largest Sum Contiguous Subarray problem, also known as the Maximum Subarray Problem, involves finding a contiguous subarray within a given array that has the largest sum. This is a classic algorithmic problem that can be efficiently solved using Kadane's Algorithm. Array: [-2, 1, -3, 4, -1, 2, 1, -5, 4] -2 1 -3 ...

Read More

PHP Pagination

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

Pagination in PHP refers to the process of dividing a large set of data into smaller, more manageable sections called "pages." It is commonly used in web applications to display a limited number of records or results per page, allowing users to navigate through the data easily. Pagination is essential when dealing with large data sets because displaying all the records on a single page can lead to performance issues and an overwhelming user interface. By implementing pagination, you can improve the user experience and optimize the performance of your application. How Pagination Works ...

Read More
Showing 31–40 of 802 articles
« Prev 1 2 3 4 5 6 81 Next »
Advertisements