0

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.

1 Answer 1

10
foreach($site->latestBookmarks() as $bookmark) {
  echo $bookmark['title'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

@ritch, note the as versus =.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.