温馨提示×

php strtolower能批量转换吗

PHP
小樊
83
2024-11-18 21:38:23
栏目: 编程语言
PHP开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

是的,strtolower() 函数在 PHP 中可以批量转换字符串。您可以使用循环遍历数组中的每个元素并将其转换为小写。以下是一个示例:

<?php
$strings = array("Hello", "WORLD!", "ExaMple", "WITH", "UPPER", "AND", "LOWERCASE");

foreach ($strings as $key => $value) {
    $strings[$key] = strtolower($value);
}

print_r($strings);
?>

输出结果:

Array
(
    [0] => hello
    [1] => world!
    [2] => example
    [3] => with
    [4] => upper
    [5] => and
    [6] => lowercase
)

在这个示例中,我们创建了一个包含大写和小写字符串的数组 $strings。然后,我们使用 foreach 循环遍历数组中的每个元素,并使用 strtolower() 函数将其转换为小写。最后,我们打印出修改后的数组。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:php strtolower能转换中文吗

0