Pradeep Kumar

Pradeep Kumar

1,035 Articles Published

Articles by Pradeep Kumar

Page 7 of 104

PHP Program for Largest Sum Contiguous Subarray

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 370 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

Measuring Script Execution Time in PHP

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

In PHP, measuring script execution time is crucial for performance optimization and debugging. PHP provides several built−in functions to measure how long your code takes to execute, each with different levels of precision. Using microtime() Function The most commonly used method for measuring execution time with microsecond precision ? Script execution time: 0.045123 seconds Using time() Function For basic timing with second−level precision ? Script execution time: 2 seconds Using hrtime() Function (PHP 7.3+) The most precise method available, providing ...

Read More

Insert String at Specified Position in PHP

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

In PHP, you can insert a string at a specified position within another string using various methods. The most common approaches include string concatenation with substr() and the substr_replace() function. Using String Concatenation with substr() This method breaks the original string into two parts and concatenates the insert string between them − Hello beautiful World! The substr() function extracts portions before and after the specified position, then the dot operator concatenates all three parts together. Using substr_replace() Function The substr_replace() function provides a more direct approach for inserting ...

Read More

Implementing Callback in PHP

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

In PHP, callbacks are functions that can be passed as arguments to other functions and executed at a later time. This powerful feature allows for flexible and reusable code design. PHP offers multiple ways to implement callbacks depending on your specific needs. There are three common approaches to implement callbacks in PHP ? Callback Functions Anonymous Functions (Closures) Callable Objects Callback Functions Callback functions are regular named functions that can be passed as arguments to other functions. The receiving function can then execute the passed ...

Read More

How to Use a Switch case \'or\' in PHP

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

In PHP, the switch-case statement does not directly support the logical OR (||) operator to combine multiple cases. However, there are several effective approaches you can use to achieve similar functionality when you need multiple values to trigger the same action. Using If-Else Statements Instead of using a switch statement, you can utilize if-else statements with logical "or" operators ? Value is 1, 2, or 3 We define an array $validValues that contains the values we want to check against. The in_array() function determines if $value exists within the array. ...

Read More

How to Test a URL for 404 error in PHP?

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

In PHP, testing a URL for 404 errors is essential for validating links and ensuring proper user experience. PHP offers several methods to check URL status codes, each with different levels of efficiency and control. Using file_get_contents() The simplest approach uses file_get_contents() with a custom stream context to handle errors gracefully ? This method creates a stream context with ignore_errors set to true, preventing PHP from throwing warnings on HTTP errors. The $http_response_header variable is automatically populated with headers from the last HTTP request. Using get_headers() A more efficient approach using ...

Read More

How to Send HTTP Response Code in PHP

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

In PHP, you can send HTTP response codes to communicate the status of a request to the client. This is essential for proper web communication and helps browsers, APIs, and other clients understand how to handle the response. Using http_response_code() Function The http_response_code() function is the simplest method to set HTTP response codes in PHP 5.4+: This function must be called before any output is sent to the client. You can also retrieve the current response code by calling it without parameters: Using header() Function The header() ...

Read More

How to Send a GET Request from PHP

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

In PHP, you can send GET requests to retrieve data from external APIs or web services using several built−in methods. Each approach offers different levels of functionality and control over the request process. Using file_get_contents() The simplest method for sending GET requests uses the file_get_contents() function, which is ideal for basic requests without custom headers or complex configurations ? Note: Ensure that allow_url_fopen is enabled in your PHP configuration for this method to work with remote URLs. With Context Options You can customize the request by creating a context ...

Read More

How to Select and Upload Multiple files with HTML and PHP, using HTTP POST

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

HTML and PHP are commonly used together to create dynamic web applications. When it comes to uploading multiple files from an HTML form to a PHP script, the standard method is to use the HTTP POST method with multipart form encoding. HTML Form for Multiple File Upload Create an HTML form that allows users to select multiple files for uploading. Use the element with the multiple attribute to enable multiple file selection. Set the form's enctype attribute to "multipart/form-data" to handle file uploads − Multiple File Upload ...

Read More
Showing 61–70 of 1,035 articles
« Prev 1 5 6 7 8 9 104 Next »
Advertisements