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 trialVidit Shah
6,037 PointsWhat's wrong with my php code?
<?php
function hello() {
echo "hello,world!";
}
hello();
//This code Doesnt work
$current_user = "Vidit";
function check(){
global $current_user;
if($current_user=="Vidit")
{
echo "Hey! This is Vidit";
}
else {
echo "Sorry!";
}
}
?>
my second function is not working
Niclas Valentiner
8,947 PointsI don't see a function call for check(). It's either not working because you didn't call the function or there is more code you haven't shared which contains the actual problem.
1 Answer
mikes02
Courses Plus Student 16,968 PointsWhat was stated above is correct, you aren't calling your check function in your code, you need:
<?php
function hello() {
echo "hello,world!";
}
hello();
$current_user = "Vidit";
function check() {
global $current_user;
if($current_user=="Vidit") {
echo "Hey! This is Vidit";
} else {
echo "Sorry!";
}
}
check();
?>
With that in place you will see "hello,world!Hey! This is Vidit" on your screen.
Andrew Shook
31,709 PointsAndrew Shook
31,709 PointsWhat exactly isn't working?