循环数组,奇怪的输出

发布于 2024-12-09 15:50:31 字数 727 浏览 0 评论 0原文

我有一个看起来像这样的数组,

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坚持沉默 2024-12-16 15:50:31

当您尝试回显实际上是字符串的数组元素时,就会发生这种情况。例如。

$string = "hello";
echo $string[1]; // echos "e"

确保 $results 的结构符合您的预期,并且您在正确的变量上使用 print_r() 。

另请参阅: 按字符访问和修改字符串 文档

This happens when you try and echo an array element thats actually a string. eg.

$string = "hello";
echo $string[1]; // echos "e"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文