Jump to content

Recommended Posts

conditions are not terminated by semicolons.  Conditions  use { } brackets to mark the beginning and end of what you want executed if they evaluate true.  But, if you are only wanting to execute one expression if it evaluates true, you don't need the { } brackets.  Examples:

 

if (condition)
  expression1; // will be executed if condition is true

 

if (condition) {
  expression1; // will be executed if condition is true, same as first one
}

 

if (condition)
  expression1; // will be executed if condition is true
  expression2; // will be executed regardless of whether condition is true or not, as it is not tied to the condition

 

if (condition) {
  expression1; // will be executed if condition is true
  expression2; // will be also only be executed if condition is true, since it is wrapped inside the brackets
}

 

So technically, you could have written your code like this:

<?php
if(setcookie("pam","Pamela is great"))
  echo "The deal is done!";
else
  echo "No cookie for you!";
?>

Link to comment
https://forums.phpfreaks.com/topic/160429-solved-if-and-else/#findComment-846617
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.