Array to string conversion in html body

Issue

This Content is from Stack Overflow. Question asked by Rollo

I need help with this PHP code as I try to implement it into my html body I get an array to string conversion error.

I came up with this, I want to print out the unordered list without concatenations.

<?php foreach($links as $title):?>
        <ul>
            <a href = "<?= $links ?>"><?= $title ?></a>
        </ul>
 <?php endforeach ?>

I made this code up from this hashes of arrays.

$links = [
    ['title' => 'Slack', 'href' => 'https://slack.com'],
    ['title' => 'Google','href' => 'https://www.google.ca'],
    ['title' => 'Stack', 'href' => 'https://stackoverflow.com']
];



Solution

Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?