To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE/YASS documentationAlternative values

Alternative values are a powerful way of safely setting a value without relying on the built-in is_set function. Alternative values were added in ZPE version 1.7.11 (September 2019).

An alternative value is a syntax that allows the programmer to define a fall back value in the case that a value is undefined or null.

The alternative value is specified with the ?? syntax after an expression:

⟨expression1⟩ ?? ⟨expression2⟩

For example:

YASS
$search = input("Please insert the username you are looking for.")
$users = ["jamie1" => "Jamie Balfour", "john1" => "John Balfour"]

print($users[$search] ?? "User not found")
    

If the user were to input a username that does not exist in the array, the print method would not print undefined but would instead print User not found because of the ?? specifying an alternative value.

Comments
Code previewClose
Feedback 👍
Comments are sent via email to me.