修剪字符串
这可能很愚蠢,但我现在已经绞尽脑汁反对它了..
$values 包含以下文本:
'58','val','val','val','2011-05-12 21-41-42','','0','micahstesttest',
Why won't cut the last comma?
trim($values, ",");
编辑 - 这就是 $values 的生成方式:
$values = "";
foreach($users_table as $k=>$v){ $values .= "'$v',"; }
trim($values, ",");
This may be dumb but I've been beating my head against it for a bit now..
$values contains this text:
'58','val','val','val','2011-05-12 21-41-42','','0','micahstesttest',
Why won't this trim the last comma?
trim($values, ",");
EDIT - this is how $values is being generated:
$values = "";
foreach($users_table as $k=>$v){ $values .= "'$v',"; }
trim($values, ",");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
字符串末尾后是否有可能有多余的空格?尝试打印它并用引号引起来。
Is it possible that there's extra whitespace after the end of your string? Trying printing it surrounded with quotes.
最后一个逗号
,
之后可能有一些额外的字符。请参阅以下代码:OUTPUT
尝试使用
var_dump
检查原始字符串,如下所示:You probably have some extra character after last comma
,
. See this code:OUTPUT
Try checking your original string with
var_dump
like this:我屈服了。
如果有人知道我做错了什么,我很乐意听到。这让我难住了。
I caved.
If anyone knows what I was doing wrong, I'd love to hear it though. It's got me stumped.
这对我有用,
你也可以这样做
,或者
如果你只想将数组的值放入新数组中,只需使用 array_values()
this works for me
you could also do this
or
if you just want to put the values of an array in to a new array just use array_values()