IF statement inside PHP function not working?

This is very basic, I know - but I simply can't figure out why this short section of PHP code isn't working for me? I'm trying to get a IF statement happening in my function, and then execute the function somewhere on my document so it returns "../".

<?php $confirm = "yes"; ?>  

<?php
   function clientarea() {
      if (isset($confirm)) {
         if ($confirm == "yes") {
             echo "../";
         }
      }
   }
?>

<img src="<?php clientarea(); ?>images/logo.png" alt="Logo" />

Any ideas why this code doesn't work for me?

Answers


This should work better:

<?php $confirm = "yes"; ?>  

<?php
   function clientarea($confirm) {
      if (isset($confirm)) {
         if ($confirm == "yes") {
             echo "../";
         }
      }
   }
?>

<img src="<?php clientarea($confirm); ?>images/logo.png" alt="Logo" />

You can better use booleans instead of "yes" or "no"...

I modified your code:

<?php $confirm = true; ?>  

<?php
   function clientarea($confirm) {
      if ($confirm) {
             echo "../";
      }
   }
?>

<img src="<?php clientarea($confirm); ?>images/logo.png" alt="Logo" />

Need Your Help

Disabling the fullscreen editing view for soft keyboard input in landscape?

android android-softkeyboard android-input-method

On Android devices that use soft keyboards, I want to prevent the fullscreen keyboard editing view (shown below) from appearing when in landscape mode (i.e. I want to see only the soft keyboard its...

jasmine: spyOn(obj, 'method').andCallFake or and.callFake?

javascript jasmine

I want to mock test data in my Jasmine tests. Here are two versions:

PHP ELSE IF statement

php rounding if-statement

unable to get my else if statement to work, does anyone have any ideas? it works without the else if....