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

Thread.sleep's interrupt handling calling Thread.sleep

java multithreading sleep

I'm developing some program that has to read log files and I thought that I built a smart mechanism in it, turns out the code does not even compile...

How does this sfrw(x,x_) macro work (msp430)?

c gcc macros interrupt msp430

I just ran into an interesting phenomenon with msp430f5529 (TI launchpad). After trying different approaches I was able to find a solution, but I don't understand what is going on here.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.