Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

How to convert a string into number in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 343 Views

PHP provides several methods to convert strings into numbers. The most common approaches are type casting, built-in functions like intval() and floatval(), and adding zero to the string. Using Type Casting Type casting is the most direct method to convert a string to a specific numeric type ? Original String: 150 Converted Integer: 150 Using floatval() Function For decimal numbers, use floatval() to convert strings to floating-point numbers ? String: 100.56 Number (Float): 100.56 Using intval() Function The intval() function ...

Read More

How to convert number to month name in PHP?

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

In PHP, you can convert a month number to its corresponding month name using several built-in functions. The most common approaches are using date() with mktime() or the DateTime class. Using date() with mktime() The mktime() function creates a timestamp, which can then be formatted using date() to get the month name ? Month number: 11 Full month name: November Short month name: Nov Using DateTime Class The DateTime class provides a more object-oriented approach for month conversion ? Month number: 12 Full ...

Read More

How to create comma separated list from an array in PHP?

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

Creating a comma-separated list from an array in PHP is efficiently done using the built-in implode() function. This function joins array elements with a specified delimiter string. Syntax implode(separator, array) Parameters separator: The string to use as a delimiter between array elements (optional, defaults to empty string). array: The array whose elements you want to join. Basic Example Here's a simple example of creating a comma-separated list from a numeric array − Original array: Array ( [0] => 100 [1] => 200 [2] => 300 [3] => 400 [4] => 500 ) Comma separated list: 100, 200, 300, 400, 500 Handling Whitespace in Array Elements When array elements contain extra whitespace, you may want to trim them before creating the list −

Read More

How to get a variable name as a string in PHP?

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

In PHP, getting a variable name as a string is useful for debugging and dynamic programming. There are several approaches to retrieve variable names, each with different use cases and limitations. Using Variable Variables The simplest approach uses PHP's variable variables feature to demonstrate the relationship between variable names and their string representations ? This will produce the following output ? This is it! Using $GLOBALS Array A more practical approach searches through the $GLOBALS array to find a variable by its value and return its name ? ...

Read More

How to trim all strings in an array in PHP ?

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

In PHP, you can trim all strings in an array by removing leading and trailing whitespace from each element. There are several methods to achieve this, with array_map() being the most common approach. Using array_map() The array_map() function applies the trim() function to each element of the array ?

Read More

PHP to check substring in a string

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 318 Views

In PHP, you can check if a substring exists within a string using the strpos() function. This function returns the position of the first occurrence of a substring, or false if not found. Using strpos() Function The strpos() function is case-sensitive and returns the numeric position of the substring or false if not found ? String = How I Met Your Mother Substring = Mother Substring found successfully Example with Substring Not Found Here's an example where the substring is not present in the string ? ...

Read More

How to add days to $Date in PHP?

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

In PHP, you can add days to a date using several methods. The most common approaches are using strtotime() with date() or the object-oriented DateTime functions. Method 1: Using strtotime() and date() The simplest approach uses strtotime() to parse date strings and add time intervals ? Displaying date... Date = 2019-11-11 Displaying updated date... 2019-12-01 Method 2: Using DateTime Functions For more object-oriented approach, use date_create(), date_add(), and date_format() functions ? Displaying Date...2019/11/11 Displaying Updated Date... 2019/12/06 Method 3: Using DateTime ...

Read More

How to convert string to boolean in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 865 Views

To convert string to boolean in PHP, you can use the filter_var() function with the FILTER_VALIDATE_BOOLEAN filter. This function recognizes specific string values and converts them to their boolean equivalents. Basic String to Boolean Conversion The filter_var() function converts string values to boolean based on predefined rules − bool(true) bool(true) bool(true) bool(true) bool(false) bool(false) bool(false) bool(false) bool(false) Using FILTER_NULL_ON_FAILURE Flag You can use the FILTER_NULL_ON_FAILURE flag to return null for invalid boolean strings instead of false − bool(true) bool(false) NULL NULL ...

Read More

How to get first day of week in PHP?

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

In PHP, you can get the first day of the week using the date() and strtotime() functions. The default first day varies by locale, but you can specify whether you want Monday or Sunday as the first day. Getting Monday as First Day By default, PHP considers Monday as the first day of the week when using "this week" − First day = Monday - 09/12/2019 Getting Sunday as First Day To get Sunday as the first day of the week, you can use different approaches − ...

Read More

How to get the first element of an array in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 365 Views

In PHP, there are several methods to get the first element of an array. The approach depends on whether you're working with indexed arrays, associative arrays, or need to preserve the array pointer. Using array_values() for First Element The most reliable method works with both indexed and associative arrays ? First element: 150 Using reset() Function The reset() function moves the internal pointer to the first element and returns its value ? First element: 150 Using array_slice() Method Extract the ...

Read More
Showing 22551–22560 of 61,297 articles
Advertisements