Skip to content
Advertisement

How to check if property is defined and provide a substitute in PHP?

My service sometimes returns

JavaScript

set and sometimes not and my code

JavaScript

throws error

JavaScript

in that case.

What is the shortest way to check if property set and if it is, then return it’s value, but if it isn’t then return some predefined value like 0 or NULL?

Advertisement

Answer

Ternary operator,if it`s not set the price will be 0

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement