How to remove spaces in array keys names in php?(如何在php中删除数组键名称中的空格?)
问题描述
我正在尝试删除数组键名称中的所有空格,即 str_replace(' ','',$value) (或者最坏的转换场景将它们替换为下划线 (_) )
I am trying to remove all spaces in array keys names i.e. str_replace(' ','',$value) (or worst cast scenario replace them with underscores (_) )
并且我正在尝试在我的多维数组的最深层次(如下所示)执行此操作(因为其他层/层次没有空格(感谢上帝!))
and I am trying to do this at the deepest level (shown below) of my multidimensional array (because other layers/levels don't have spaces (THANK GOD!))
到目前为止,我的尝试没有结果:
So far my attempts have been fruitless :
上面的代码不起作用,但是如果我把 print_r($value);在循环结束时,您可以清楚地看到空格正在被删除,只是不知何故最终结果以空格结束(STILL).
The codes above do not work, however if I put print_r($value); at the end of the loop you can clearly see that spaces are being removed, just somehow the end result ends up being with spaces (STILL).
整个循环如下所示:
你可以在这里看到整个数组的样子:
And you can see how the whole array looks like here:
如何使用我选择的键和值(在 php 中)将数组添加到另一个数组的每个元素?
有什么建议吗?:)
推荐答案
这将有助于:
测试如下:
输入:
输出:
这篇关于如何在php中删除数组键名称中的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!