如何在php中修剪数组值的空格 [英] How to trim white spaces of array values in php

查看:28
本文介绍了如何在php中修剪数组值的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组如下

$fruit = array('  apple ','banana   ', ' , ',     '            cranberry ');

我想要一个数组,其中包含两边没有空格的值,但它可以包含空值如何在 php.the 中执行此操作.输出数组应该是这样的

I want an array which contains the values without the white spaces on either sides but it can contain empty values how to do this in php.the output array should be like this

$fruit = array('apple','banana', ',', 'cranberry');

推荐答案

array_maptrim 可以胜任这项工作

array_map and trim can do the job

$trimmed_array = array_map('trim', $fruit);
print_r($trimmed_array);

这篇关于如何在php中修剪数组值的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆