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

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

问题描述

我有一个数组如下:

  $ =水果阵列('苹果','香蕉',',','小红莓');

我想它包含的值没有空格上两侧的阵列,但它可以包含空值是如何做到这一点php.the输出数组中应该是这样的。

  $ =水果阵列('苹果','香蕉',',','小红莓');


解决方案

array_map 削减 可以做的工作。

  $ trimmed_array = array_map('微调',$水果);
的print_r($ trimmed_array);

I have an array as follows

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

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_map and trim can do the job

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

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

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