循环数组,奇怪的输出
我有一个看起来像这样的数组,
Array
(
[candidate_id] => 1
[first_name] => Simon
[surname] => Ainley
[gender] => male
[talent] => presenter
[DOB] => 1987-06-12
[Location] => Huddersfield
[height] => 6' 3"
[eyes] => blue
[hair] => brown
[hair_length] => short
[accents] => Native english
[training] => none
[unions] => Actors guild
[date_created] => 2011-10-11 00:00:00
)
但是当我执行以下操作时,
<?php foreach ($results as $k => $v) : ?>
<?php print_r($v); ?>
<?php endforeach; ?>
使用它我得到输出,
1 S A m p 1 H 6 b b s N n A 2
I have an array that looks like this,
Array
(
[candidate_id] => 1
[first_name] => Simon
[surname] => Ainley
[gender] => male
[talent] => presenter
[DOB] => 1987-06-12
[Location] => Huddersfield
[height] => 6' 3"
[eyes] => blue
[hair] => brown
[hair_length] => short
[accents] => Native english
[training] => none
[unions] => Actors guild
[date_created] => 2011-10-11 00:00:00
)
However when I don the following,
<?php foreach ($results as $k => $v) : ?>
<?php print_r($v); ?>
<?php endforeach; ?>
Using this I am getting output,
1 S A m p 1 H 6 b b s N n A 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您尝试回显实际上是字符串的数组元素时,就会发生这种情况。例如。
确保 $results 的结构符合您的预期,并且您在正确的变量上使用 print_r() 。
另请参阅: 按字符访问和修改字符串 文档。
This happens when you try and echo an array element thats actually a string. eg.
Make sure the structure of $results is what you think it is and you are using print_r() on the correct variable.
See also: String access and modification by character Docs.