foreach 修剪字符,我没有告诉它!
我已将其清理到我知道存在问题的地方。坦率地说,我有一个 foreach 语句,将结果的一个字符全部截断。下面评论中的示例。
print_r($getarticlemultiarray);
/// this print_r returns good values like [title] => titletext [body] => bodytext
foreach ($getarticlemultiarray as $zyz) {
echo $zyz['title'];
// here is the problem. This echo statement is only throwing out 1 character
// for example with the values in the example above it's just echoing a 't'.
} // end foreach
这个 foreach 嵌套在另一个 foreach 中,但我没有对字符串长度做任何事情,并且我没有在其他任何地方使用 $zyz 。没什么奇怪的,只是普通的单词,也没有特殊字符。
I've cleaned this up to where I know there is an issue. Bluntly I've got a foreach statement cutting off all by one character of the results. Example in comments below.
print_r($getarticlemultiarray);
/// this print_r returns good values like [title] => titletext [body] => bodytext
foreach ($getarticlemultiarray as $zyz) {
echo $zyz['title'];
// here is the problem. This echo statement is only throwing out 1 character
// for example with the values in the example above it's just echoing a 't'.
} // end foreach
This foreach is nested inside another one, but I'm not doing anything with string lengths, and I am not using $zyz anywhere else. Nothing strange but normal words with no special characters either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您所说的,看来您的 print_r 本质上是
在这种情况下,您的
foreach
将$zyz
设置为titletext
和正文文本
,分别。这些字符串没有“标题”键。 PHP 会将这些键视为 0,进而返回第一个字符(因此您会看到“t”)。看来你不必在这里循环。Based on what you have said, it looks like your print_r is essentially
In that case, your
foreach
is setting$zyz
totitletext
andbodytext
, respectively. These strings have no 'title' key. PHP will treat these key as 0 which in turn returns the first character (hence why you see a 't'). Seems like you don't have to loop here.