PHP strtolower Function | Make a String Lowercase

PHP strtolower is an inbuilt function in PHP. It converts a PHP string to lowercase characters. In this article, we will discuss this function. Also, we will discuss a few examples of using it.

Also, you can convert a string to uppercase characters using PHP strtoupper Function.

Syntax

strtolower ($string)

Parameters

The strtolower function expects only one parameter. Pass the string you need to convert to lowercase as the parameter.

Return Value

The function returns a string after converting all alphabetical characters to lowercase.

Input: strtolower('CONCATLY')
Output: concatly

Input: strtolower('BRINGING KNOWLEDGE TOGETHER')
Output: bringing knowledge together
PHP strtolower Function | String to Lowercase

Examples

Let’s consider a couple of examples of using the function.

Example 1: Simple String

You can pass an alphabetical string to the function and convert it to lowercase.

<?php

	$string = 'THIS IS A STRING 234';
	$uppercase = strtolower($string);

	echo $uppercase;
	/* this is a string 234 */

?>

Example 2: Array of Strings

You can use the PHP array_map Function to directly convert all the strings in an array to lowercase by passing strtolower as the callback function.

<?php

	$arrayOfStrings = array(
		'STRING 1',
		'STRING 2 is UPPER',
		'ANOTHER STRING'
	);

	$lowerCaseArray = array_map('strtolower', $arrayOfStrings);
	print_r($lowerCaseArray);
	/*
	Array
	(
	    [0] => string 1
	    [1] => string 2 is upper
	    [2] => another string
	)
	*/

?>

Conclusion

We discussed the PHP strtolower in this article. You can read more about it on the Official PHP Documentation. Also, you can read about more String Functions on Concatly.

Spread the Knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *