-1

How to change an array small letter.

I have tried like ---

$data = array_map('strtolower', $data);

it return me an error like ---

Warning: strtolower() expects parameter 1 to be string, array given

so i have tried like ---

$data = array_change_key_case($data, CASE_UPPER);

But that is also changing all the strings into small letters.

My guess i have multiple array inside an array, that's why none of this is working for me.

$data =
    Array
    (
        [0] => Array
            (
                [name] => Samsung GT-N7100 Galaxy Note II 16GB
            )

        [1] => Array
            (
                [name] => Samsung GT-i9100 Galaxy S II
            )

        [2] => Array
            (
                [name] => Samsung GT-i9300 Galaxy S III 16GB
            )

        [3] => Array
            (
                [name] => Apple iPhone 5 16GB
            )

        [4] => Array
            (
                [name] => Samsung GT-P5110 Galaxy S 4 10.1 16GB
            )

        [5] => Array
            (
                [name] => Samsung UE46ES6715
            )

        [6] => Array
            (
                [name] => Samsung 830 Series MZ-7PC128 128GB
            )

        [7] => Array
            (
                [name] => Samsung GT-N8000 Galaxy Note 10.1 16GB
            )

        [8] => Array
            (
                [name] => Samsung 830 Series MZ-7PC256 256GB
            )

        [9] => Array
            (
                [name] => Samsung UE46ES6715
            )

        [10] => Array
            (
                [name] => Samsung GT-2423 Galaxy Tab 4 10.1 16GB
            )

Any suggestion how can i convert an array(inside multiple array) into lowercase in PHP.

2
  • Why don't you use strtolower() on the previous output ? (your older questions) Commented Oct 11, 2015 at 15:08
  • @PedroLobito this is using in a different use Commented Oct 11, 2015 at 15:14

2 Answers 2

5

Use array_walk_recursive:

array_walk_recursive($data, function (&$item) {
    $item = strtolower($item);
});

var_dump($data);
Sign up to request clarification or add additional context in comments.

Comments

0

Simply like this

function my_array_tolowcase(&$array)
{
    foreach($array as &$arr)
    {
        $arr["name"] =strtolower($arr["name"]);
    }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.