Capitano
Capitano

Reputation: 43

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?

Upvotes: 0

Views: 58

Answers (1)

nice_dev
nice_dev

Reputation: 17805

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>";

Upvotes: 1

Related Questions