ds08541 2016-02-11 16:41
浏览 34
已采纳

如何删除数组值中的空格? [重复]

This question already has an answer here:

I'm iterating through an XML and get a specific node. This node will be saved into an array but there is a problem. The array values have a space like this:

array(4) { ["host"]=> string(55) " localhost " ["username"]=> string(50) " root " ["dbName"]=> string(56) " test " ["dbPass"]=> string(52) " 123456 " }

You can see each values have a space before and after the value. The final result that I want achieve is this:

array(4) { ["host"]=> string(55) "localhost" ["username"]=> string(50) "root" ["dbName"]=> string(56) "test" ["dbPass"]=> string(52) "123456" }

If I do trim($array_node) I get an empty array.

</div>
  • 写回答

2条回答 默认 最新

  • dougehe2022 2016-02-11 16:45
    关注

    If $array_node is the array itself, rather than one of the values within it, then that would explain why you are getting back an empty array.

    A quick solution to apply the 'trim' function to all the values in the array would be the following:

    $result_array = array_map('trim', $source_array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?