Search code examples
phppostisset

Asking for 2 isset`s as an Function parameter


Hey guys quick Question.

Is thecode below correct?

if (isset($_POST['testSendDe']) || isset($_POST["testSendEn"])) {"function"}

Is it possible to as for 2 isset`s as an Function Parameter in PHP?


Solution

  • You can use null coalescing operator for this to make it one liner like below:

    <?php
    
    echo "<td>" . (($_POST['vorname'] ?? false) || ($_POST["firstName"] ?? "")) . "</td>";
    

    Update:

    If you wish to print some text of your own than what is present in those keys, you could do the below:

    <?php
    
    echo "<td>" . (($_POST['vorname'] ?? ($_POST["firstName"] ?? false)) ? "printing because either of them is set" : "printing because none of them is set") . "</td>";