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 Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Review Basics

MacKenzie T. Stout
MacKenzie T. Stout
23,972 Points

How 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.

output.php
<?php
include 'flavor.php';
  return get_flavor($flavor);
echo "Hal's favorite flavor of ice cream is ____.";

?>

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi 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
MacKenzie T. Stout
23,972 Points

Thank you, I was making it too complex!