Welcome to the Treehouse Community
Looking to learn something new?
How do I echo only parts of an array in PHP?
I've got this link here...
<a href="museum-pages/British-Dental-Association-Museum.php" id="" title="British-Dental-Association-Museum">British Dental Association Museum</a>
echo'd from a database, I know the result from a database query comes back as an array, but how do I echo only this part of the link...
? I'm sure there is a function for it, but not sure where to look?
I'd be really grateful for your help!
It's hard to say without seeing the code and the explode function is helpful for sure. You can also just grab things from an array by adding the index number (starting at zero) of what you want to include in the link.
Here's a simple example:
<?php $array = ["hyperlink text","example_domain","three","four"]; echo "<a href=http://" . $array . ".com>" . $array . ".</a>"; ?>
Hope this helps!