Jump to content

SImple solution....


dreamwest

Recommended Posts

A few things. Firstly, number are not surrounded by quotes within php, that makes them strings. Secondly, variables are not interpolated within single quotes (they are within double).

 

You've also a few minor syntax errors.

 

$days = 4;

if ($days == 0)
  echo 'no days'; 
else
  echo $days;

 

ps: I (and most others) prefer to stick to using braces to group blocks of code.

 

$days = 4;

if ($days == 0) {
  echo 'no days'; 
} else {
  echo $days;
}

Link to comment
https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722052
Share on other sites

Try this:

 

 $days = '4';

if ($days == '0') { echo ("no days"); }
else { echo ("$days"); }

 

Sorry but I must comment. That is an absolutely terrible coding style to get into the habit of. Fine for tiny scripts like this, but start writing decent sized applications and all readability is out the window.

Link to comment
https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722054
Share on other sites

Thanks for the help...

 

I want to take it a step further and add ifelse, i feel like im close but still chasing my tail

 

Heres what ive got so far:

 

$days = 2;
$hours = 0;
$minuets = 4:

if ($days == 0) {
  echo 'Added '.$hours.' hours and '.$minutes.' minuets ago'; 
} else {
echo 'Added '.$days.' Days ago';
} elseif ($hours == 0) {
  echo 'none'; 
} else { 
echo 'Added '.$hours.' Hours ago';
}

 

My goal is to make it so if there is "0" in any of the variables only the variables with 1 or more will display in a message

Link to comment
https://forums.phpfreaks.com/topic/138126-simple-solution/#findComment-722068
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.