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 trialMacKenzie T. Stout
23,972 PointsHow do I call a function from another file and assign it to a variable?
I don't understand how to call a function from another file and assign it to a variable.
<?php
include 'flavor.php';
return get_flavor($flavor);
echo "Hal's favorite flavor of ice cream is ____.";
?>
1 Answer
Chase Marchione
155,055 PointsHi MacKenzie,
You'll want to ditch the return keyword (the return keyword is used to return the program's control to a calling module... source: http://php.net/manual/en/function.return.php), and instead store the result of the get_flavor() function call into the variable $flavor.
<?php
include 'flavor.php';
$flavor = get_flavor();
echo "Hal's favorite flavor of ice cream is ____.";
?>
Hope this helps!
MacKenzie T. Stout
23,972 PointsMacKenzie T. Stout
23,972 PointsThank you, I was making it too complex!