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! While you're at it, check out some resources Treehouse students have shared here.
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 trialTrần Phúc
2,264 Pointsissue combined array_walk and use <tag>table in php
I want use it for more convenient. But i don't know why it no work
<?php $movie = array(
"title"=>"The Empire Strikes Back",
);
$movie["year"] ="1980";
$movie["director"] ="Irvin Kershner";
$movie["imdb_rating"] ="8.8";
$movie["imdb_ranking"] ="11";
function display($key,$value){
"<tr>"
"<th>"echo $key"</th>"
"<td>"echo $value"</td>"
"</tr>"
}
?>
<h1><?php echo $movie["title"].$movie["year"] ?></h1>
<?php array_walk($movie, 'display') ?>
<tr>
<th>Director</th>
<td>Robert Zemeckis</td>
</tr>
<tr>
<th>IMDB Rating</th>
<td>8.5</td>
</tr>
<tr>
<th>IMDB Ranking</th>
<td>53</td>
</tr>
</table>
1 Answer
Mike Costa
Courses Plus Student 26,362 PointsMy guess is that inside your display function, you're not returning or echoing anything. If just strings that are just kinda hanging around.
function display($key,$value){
"<tr>"
"<th>"echo $key"</th>"
"<td>"echo $value"</td>"
"</tr>"
}
Try echoing the string together
function display($key,$value){
echo "<tr><th>{$key}</th><td>{$value}</td></tr>";
}
Or if you'd prefer concatenation.... Try echoing the string together
function display($key,$value){
echo "<tr><th>" . $key . "</th><td>" . $value . "</td></tr>";
}
Trần Phúc
2,264 PointsThanks
Thomas Dimnet
Python Development Techdegree Graduate 43,629 PointsThomas Dimnet
Python Development Techdegree Graduate 43,629 PointsHey Tran,
if you do not find a solution yet, try this :
You do not have to 'echo' every variables. You still have to work on it but now it displays your results on the screen ;)