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 trialRobbie Thomas
31,093 PointsPHP Returning Values help.
Although this particular PHP class doesn't present a code challenge, I do want to get this right. On the Returning Values code that Mr. Paulk has up, I swear, I have the same code. But he get's a value back and all I get is a blank screen. What am I doing wrong?
<?php
function add_up($a, $b){
$arr = array{
$a,
$b,
$a + $b
};
return $arr;
}
$value = add_up(2, 4);
print_r($value[2]);
?>
1 Answer
Robbie Thomas
31,093 PointsForget it, found out the problem.
It should be this:
<?php
function add_up($a, $b){
$arr = array(
$a,
$b,
$a + $b
);
return $arr;
}
$value = add_up(2, 4);
echo $value[2];
?>
Instead of array{}, it's supposed to be array().
Robbee F'ed up.