php 怎么将数组转大写

php 怎么将数组转大写,第1张

php 怎么将数组转大写

php将数组转大写的方法:1、创建一个PHP示例文件;2、定义一个关联数组;3、使用foreach语句遍历数组;4、使用strtoupper函数将数组元素转为大写即可。

本文 *** 作环境:Windows7系统、PHP7.1版、DELL G3电脑

php 怎么将数组转大写?

PHP关联数组中如何更改键值为大写

我们有这样一个数组:

$fruits = array('A' => 'Apple', 'B' => 'Banana', 'c' => 'Cherry', 'o' => 'Orange');

我们将里面所有的数组元素值转为大写:

<?php
header("Content-type:text/html;charset=utf-8");
$fruits = array('A' => 'Apple', 'B' => 'Banana', 'c' => 'Cherry', 'o' => 'Orange');
var_dump($fruits);
foreach ($fruits as $key => $value){
    $fruits[$key]=strtoupper($value);
}
echo "转换为大写后:";
var_dump($fruits);
?>

使用foreach语句遍历$fruits数组,在循环中使用strtoupper($value)函数将数组元素$value转为大写,因此输出结果为:

推荐学习:《PHP视频教程》

以上就是php 怎么将数组转大写的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/681074.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存