Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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!