1

I have n php object like this:

        $test
        ->key1(1)
        ->key2(1)
        ->key3(1);

Is it possible to add a condition inside it?

like this:

   $test
   if(true) ->key1(1)
   ->key2(1)
   if(true) ->key3(1);
samanta
  • 11
  • 1
  • 1
    Why don't you just do this if ( $test ->key1(1) ->key2(1) ->key3(1)) do something; – Rain Dec 09 '17 at 12:16
  • You might want to check https://stackoverflow.com/questions/10046629/conditional-builder-method-chaining-fluent-interface and https://stackoverflow.com/questions/1189979/implementing-conditional-in-a-fluent-interface. – Progman Dec 09 '17 at 13:00
  • What do you want to check inside this condition? – shudder Dec 09 '17 at 16:10

1 Answers1

-1

what you want is

if (condition) {
    code to be executed if this condition is true;
} elseif (condition) {
    code to be executed if this condition is true;
} else {
    code to be executed if all conditions are false;
}

for example

if ($YOUR_KEY == "key1") {
    //if key1 then do something
} elseif ($YOUR_KEY == "key2") {
    //if key2 then do something
} else {
    //if none condition work than do something else
}

here $YOUR_KEY is your variable and "key1" is your value

check www.w3schools.com and http://php.net/manual for reference

Regolith
  • 2,944
  • 9
  • 33
  • 50