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 trial

PHP

What's wrong with this PHP?

Hey folks,

I've tried getting this:

<?php

echo "Randy's favorite flavor of ice cream is " . $flavor. ".";

include 'flavor.php';

$flavor = get_flavor();

return;

?>

to work in a variety of ways and it's not having it. I'm currently unable to continue so if someone could point out what's wrong with it, or post a working version I could examine so I understand the problem, I'd appreciate it.

Cheers

2 Answers

Kelly von Borstel
Kelly von Borstel
28,880 Points

I'm going to paste the code that worked for me. I don't have too much experience with php, so I'm not certain the reason your code doesn't work, but the main difference I noticed between your code and mine is the order of the statements, with include at the top, plus $flavor variable being set before it was used.

<?php
include 'flavor.php';
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is " . $flavor . ".";
?>

Thanks for that, that sorted it. I got complacent as most examples have the code in a pre-set order you don't need to mess with. I even thought it didn't make sense but didn't actually try changing it.....