Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strtolower() on an array

Tags:

arrays

string

php

Using strtolower() on an array, is there a way to make the output below lower case?

<?=$rdata['batch_id']?> strtolower($rdata['batch_id']) 
like image 399
acctman Avatar asked Dec 15 '10 01:12

acctman


People also ask

How do I use Strtolower?

strtolower() - It converts a string into uppercase. lcfirst() - It converts the first character of a string into lowercase. ucfirst() - It converts the first character of a string into uppercase. ucwords() - It converts the first character of each word in a string into uppercase.

How do I make a string all lowercase in PHP?

The strtolower() function converts a string to lowercase. Note: This function is binary-safe. Related functions: strtoupper() - converts a string to uppercase.

What is the use of In_array ()?

The in_array() function is an inbuilt function in PHP that is used to check whether a given value exists in an array or not. It returns TRUE if the given value is found in the given array, and FALSE otherwise.


2 Answers

The correct function name is strtolower(). If you want to apply this on each element of the array, you can use array_map():

$array = array('ONE', 'TWO'); $array = array_map('strtolower', $array); 

Now your array will contain 'one' and 'two'.

like image 62
s3v3n Avatar answered Oct 05 '22 02:10

s3v3n


If you have a bunch of arrays with key-value pairs and you want to change the keys to lower case only, then this is your solution:

$lower_array_keys = array_change_key_case($array, CASE_LOWER); 

Take a look at array_change_key_case.

like image 20
lasbreyn Avatar answered Oct 05 '22 01:10

lasbreyn