Articles on Trending Technologies

Technical articles with clear explanations and examples

How do you pass objects by reference in PHP 5?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 465 Views

In PHP 5, objects are automatically passed by reference, meaning that when you pass an object to a function or assign it to another variable, you're working with the same object instance, not a copy. Understanding Object References A PHP reference is an alias that allows two different variables to point to the same value. In PHP 5, object variables don't contain the actual object − they hold an object identifier that points to the object in memory. When an object is passed as an argument, returned, or assigned to another variable, these variables contain a copy ...

Read More

How to find PHP execution time?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 373 Views

In PHP, you can measure script execution time using several methods. The most common approaches include microtime() for simple timing and getrusage() for detailed CPU usage statistics. Using microtime() The simplest method to measure execution time uses microtime(true) to get timestamps ? Script execution time: 0.023456 seconds In milliseconds: 23.456 ms Using getrusage() For detailed CPU usage statistics, getrusage() provides user time and system time separately ? The process used 15.625 ms for the computations Spent 0.312 ms during system calls ...

Read More

What is faster: many ifs, or else if in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 884 Views

When choosing between multiple if statements and else if statements in PHP, else if is generally faster and more efficient due to early termination of condition checking. Multiple If Statements With multiple separate if statements, PHP evaluates every condition regardless of whether previous conditions were true ? Grade B Grade C Else If Statements With else if, PHP stops checking conditions once the first true condition is found ? Grade B Performance Comparison Approach Conditions Checked Performance Logic ...

Read More

In php, is 123==0123?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 658 Views

The answer is No. This is because 0123 represents an octal number (base 8) with a decimal equivalent of 83, while 123 is a standard decimal number. In PHP, prefixing a number with 0 indicates that it is an octal (base 8) number. This is similar to how 0x indicates hexadecimal (base 16) numbers. Basic Comparison Let's examine how PHP interprets these numbers ? int(123) int(83) The first number 123 is interpreted as a decimal number, while 0123 is treated as octal due to the leading zero. Equality ...

Read More

Stripping last comma from a foreach loop in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 948 Views

When building comma-separated strings in PHP foreach loops, you often end up with an unwanted trailing comma. There are several effective methods to handle this issue. Method 1: Using implode() Function The most efficient approach is to collect values in an array and use implode() to join them ? Apple, Banana, Orange, Mango Method 2: Using rtrim() Function Build the string with commas, then remove the trailing comma using rtrim() ? Apple, Banana, Orange, Mango Method 3: Using Counter/Flag Check ...

Read More

How can I send radio button value in PHP using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 412 Views

In PHP, you can send radio button values using JavaScript by capturing the selected value on the client side and then sending it to PHP via AJAX or form submission. Here's how to implement both approaches ? HTML Form with Radio Buttons First, create a form with radio buttons that have unique values ? First Option Second Option ...

Read More

Split string into sentences using regex in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 558 Views

In PHP, you can split text into sentences using regular expressions to handle complex sentence boundaries. This approach considers abbreviations, titles, and other edge cases that simple period-splitting would miss. Using Complex Regex Patterns The most robust approach uses multiple regex patterns to identify sentence boundaries while avoiding false positives with abbreviations and titles ?

Read More

How to upload large files above 500MB in PHP?

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

Large files can be uploaded using PHP in two ways. Both of them are discussed below − By changing the upload_max_filesize limit in the php.ini file. By implementing file chunk upload, that splits the upload into smaller pieces and assembling these pieces when the upload is completed. Method 1: Modifying PHP Settings Updating php.ini File The php.ini file can be updated as shown below − upload_max_filesize = 500M post_max_size = 500M max_input_time = 300 max_execution_time = 300 memory_limit = 512M This should be avoided since it would change the settings ...

Read More

PHP string cast vs strval function, which one should I use?

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

In PHP, you can convert values to strings using either (string) cast or the strval() function. Both methods achieve the same result but differ in their implementation and performance characteristics. String Cast vs strval() Function The strval() function is a function call whereas (string) cast is an internal type casting method. PHP uses automatic type conversion, so a variable's type is determined based on the context in which it is used. Basic Usage Examples Using String Cast Number: 42 (Type: string) Float: 3.14 (Type: string) Boolean: 1 (Type: string) ...

Read More

How to remove a function at runtime in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 733 Views

In PHP, functions have global scope and cannot be redefined once declared. However, you can work with dynamic functions using anonymous functions or variable functions that can be "removed" by unsetting the variable reference. Using Anonymous Functions with unset() You can create an anonymous function, assign it to a variable, and then unset the variable to remove the reference ? Hello, Alice! bool(true) bool(false) Practical Example with Array Processing Here's a more practical example where we create a temporary function for data processing ? ...

Read More
Showing 22481–22490 of 61,297 articles
Advertisements