PHP数组仅打印每个项目的首字母 [英] PHP array only prints first letter of each item

查看:62
本文介绍了PHP数组仅打印每个项目的首字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码仅打印每个数组项的首字母。

The code below is only printing the first letter of each array item. It's got me quite baffled.

require_once 'includes/global.inc.php';
print_r($site->bookmarkTags(1));

$index = 0;
foreach ($site->bookmarkTags(1) as $tag) {
    echo $tag['$index'];
    $index = $index + 1;
}

print_r返回:

print_r return:

Array ( [0] => Wallpapers [1] => Free )

循环:

WF


推荐答案

尝试回显$ tag,而不是$ tag ['$ index']

Try echo $tag, not $tag['$index']

由于您正在使用foreach,因此该值已从数组中获取,并且当您发布$ tag ['$ index']时,它将从'$ index'位置打印字符:)

Since you are using foreach, the value is already taken from the array, and when you post $tag['$index'] it will print the character from the '$index' position :)

这篇关于PHP数组仅打印每个项目的首字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆