Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.