Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

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

There are no comments on this page.

New comment

Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you.

Comments powered by BalfComment

Feedback 👍
Comments are sent via email to me.