打印出阵列

时间:2011-05-18 15:50:05

标签: php arrays printing echo

我有一个从$ site-> latestBookmarks()函数返回的数组,它包含以下内容:

Array ( [0] => Array ( [url] => http://support.apple.com/kb/HT1343 [title] => Mac OS X Keyboard Shortcuts ) [1] => Array ( [url] => http://stuffkit.com/30-stunning-mixed-hq-wallpapers.htm [title] => 30 Stunning Mixed HQ Wallpapers ) )

我正在尝试打印这两个项目的标题。

<?php

// index.php

include 'classes/Site.class.php';
$site = new Site();

print_r($site->latestBookmarks());

?>

<html>
<head>
    <title>Index</title>
</head>
<body>
    <h1>Latest Bookmarks</h1>
    <?php 

    while ($latestbookmarks = $site->latestBookmarks()) {
        echo $latestbookmarks['title'];
    }

    ?>
</body>
</html>

目前只是继续循环。

1 个答案:

答案 0 :(得分:10)

foreach($site->latestBookmarks() as $bookmark) {
  echo $bookmark['title'];
}