php 数组上的 strtolower()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4445984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:04:29  来源:igfitidea点击:

strtolower() on an array

phparraysstring

提问by acctman

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

在数组上使用 strtolower() 有没有办法使输出低于小写?

<?=$rdata['batch_id']?>
strtolower($rdata['batch_id'])

回答by s3v3n

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

正确的函数名称是strtolower()。如果要将其应用于数组的每个元素,可以使用array_map()

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

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

现在您的数组将包含“一”和“二”。

回答by lasbreyn

If you have a bunch of arrays with key value pair 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 it here: http://php.net/manual/en/function.array-change-key-case.php.

看看这里:http: //php.net/manual/en/function.array-change-key-case.php

回答by Ben

array_mapis preferred, but another solution is:

array_map是首选,但另一种解决方案是:

foreach($array as &$v) {
  $v = strtolower($v);
}

Note that the ampersand &makes the $vmodifiable.

请注意,&符号&使$v可修改。

回答by wajiw

do you mean strtolower?

你的意思是strtolower?

<?php echo strtolower($rdata['batch_id']); ?>

http://php.net/manual/en/function.strtolower.php

http://php.net/manual/en/function.strtolower.php

回答by RageZ

If you take a look at strtolower signature it doesn't mention any references

如果你看一下 strtolower 签名,它没有提到任何引用

string strtolower ( string $str )

so your code won't modify the value of $rdata['batch_id']

所以你的代码不会修改 $rdata['batch_id'] 的值

<?=$rdata['batch_id']?>
strtolower($rdata['batch_id']);

this code would

这段代码会

$rdata['batch_id'] = strtolower($rdata['batch_id']);