简体   繁体   中英

Printing an Array out

I have an array which is returned from the function $site->latestBookmarks() and it contains the following:

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 ) )

I am trying to print the title of both of the items.

<?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>

At the moment is just keeps on looping.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM