PHP 中的explode() 问题
我的 PHP 爆炸函数有问题。
我正在从数据库中提取一个字符串,如下所示:
column_name
0,2000,0,3000,1000,7000,1000,0,0,0
将其提取到名为 $recordset 的对象后,我使用爆炸函数从中创建一个数组...如下所示:
$array = explode(",",$recordset->column_name)
但不知何故,该数组并不像我所期望的...
这是我回显数组时得到的结果:
Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 3000
[4] => 7000
[5] => 2000
[6] => 1000
[7] => 1000
[8] => 0
[9] => 0
)
如您所见,我没有得到应有的值...但是,如果数据库中的字符串很短,请说
1000,0,1200,0
:上面的逻辑工作正常..
我不知道如何调试或解决这个问题..
请帮忙?
I'm having a problem with my explode function in PHP.
I'm pulling a string from the database as follows:
column_name
0,2000,0,3000,1000,7000,1000,0,0,0
After pulling this into an object called $recordset i'm using the explode function to make an array out of it... as follows:
$array = explode(",",$recordset->column_name)
But some how, the array is not as what i would expect...
This is what i get when i echo the array:
Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 3000
[4] => 7000
[5] => 2000
[6] => 1000
[7] => 1000
[8] => 0
[9] => 0
)
As you can see, i'm not getting the values as i should... However, if my string from the database is short, say:
1000,0,1200,0
The above logic works fine..
I'm not sure how to debug or solve this problem..
Please, help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题不在于
explode()
。问题是您从数据库中提取的字符串。如果这个字符串以某种方式连接起来,我会开始在那里寻找。如果没有,请验证数据库中的字符串,或验证访问该表的查询。查看 GROUP_CONCAT< 的文档/a>.您可以在语法中指定顺序。
The problem is not with
explode()
. The problem is the string you are pulling from the database. If this string is concatenated somehow, I would start looking there. If not, verify the string in your database, or verify the query that accesses the table.Take a look at the documentation for GROUP_CONCAT. You can specify the order in the syntax.
问题不是爆炸,正如您在此键盘中看到的,爆炸工作正常。
检查来自数据库的值,并确保它们按照您期望的顺序排列。
编辑:
这个值是如何在数据库中生成的?它是字段中的静态值,还是通过串联创建的?
The problem isn't explode, as you can see in this codepad explode is working correctly.
Check the values coming from your DB, and ensure they are in the order you expect.
Edit:
How is this value being generated in the DB? Is it a static value in a field, or is it being created from concatenation?