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 Enhancing a Simple PHP Application Integrating Validation Errors Reviewing PHP Basics

daniwao
daniwao
13,125 Points

How to call a function from different .php file!

Not sure what I'm doing wrong or what I'm missing. I would guess is that I'm either not "calling" the function the right way but I have the include or I'm not reading the directions right and I'm supposed to echo the return?

<?php include("flavor.php");

function get_flavor() { return $flavor; }

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

?>

2 Answers

Frances Leese
Frances Leese
3,235 Points

You dont need to write out the function, just call it.

so

$flavor = get_flavor();

Hello,

The function is already defined in the file you are including. The code challenge is asking you to:

  1. Include the file
  2. Assign what's returned from the function to a variable (the name of the variable is in the instructions)
  3. Use that variable inside of the echo statement to display what the function returns with the phrase that's already there.

This should make the code challenge pass.

Cheers!