-1

I currently have an index.php file and on the top i have

$pagetitle == "home";

function isThisHome(){
    if($pagetitle == "home"){
        $output = $output . 'this is home!';
    }else{
        $output = $output . 'this is not home!';
    }
    return $output;
}
echo isThisHome();

I'd expect that it would echo "this is home!" but instead it's echoing "this is not home!". Can someone help correct me to make it say "this is home"?

j08691
  • 204,283
  • 31
  • 260
  • 272

2 Answers2

0
$pagetitle == "home";

Should be

$pagetitle = "home";
ashinn
  • 109
  • 1
  • oops sorry $pagetitle = "home"; i accidentally put two in there that was my fault. but still showing "this is not my home" – user2565966 Jan 09 '16 at 22:01
0

To access variables outside the scope of a function, you need to qualify the global variable with global qualifier inside the function.

Also the assignment operator is ASSIGN (=), so IS_EQUAL (==) is not the same.

$pagetitle = "home";

function isThisHome(){
    global $pagetitle; 
    if($pagetitle == "home"){
        $output = $output . 'this is home!';
    } else{
        $output = $output . 'this is not home!';
    }
    return $output;
}
echo isThisHome();
Ryan
  • 14,392
  • 8
  • 62
  • 102