php 怎么将数组转大写
- 建站笔记
- 2022-05-09
- 440
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转为大写,因此输出结果为:
本文由白琉璃于2022-05-09发表在白琉璃源码网,如有侵权或疑问,请联系我们,谢谢。
本文链接:https://www.bailiuli.com/t/3084.html
下一篇
php怎么实现省市区查询
发表评论