1

I want to check whether monday is a holiday,if yes assign the value to $ts else go to tuesday.

  if (isset($list->hours_from_MON)) {
            $ts = $list->hours_from_MON;

        } else  (isset($list->hours_from_TUE)) {
            $ts = $list->hours_from_TUE;

The data in database is like {"hours_from_Mon":"","hours_from_Tue":"2am to 5pm"}

Here in the above case it should take ts as 2am to 5pm,but it is accepting "",i think i should use  

    if (!empty($list->hours_from_MON)) {
            $ts = $list->hours_from_MON;          

        } else  (!empty($list->hours_from_TUE)) {
            $ts = $list->hours_from_TUE;


   So that it will go to tue if,mon has no value.Am i right?Can some one help me.
raj12
  • 93
  • 11

1 Answers1

1
  • isset() will return TRUE if the variable exists and has value other than null or false

  • empty() will check if the variable is considered empty.

You can use empty() without checking if the variable is set and it will not raise a warning.

The following things are considered to be empty:

"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)
Álvaro Guimarães
  • 2,154
  • 2
  • 16
  • 24