Simple Variable Handler

/ Published in: PHP
Save to your folder(s)

Could be used across a multitude of languages. What this does is check to see if a variable is set, if it is then the variable gets left alone. If not, you define what it defaults to.

The example takes the variable $myFruit, and if it's already been defined it stays as that fruit. If not, then it is defined as the string "apple".

Copy this code and paste it in your HTML
  1. $myFruit = $myFruit ? $myFruit : "apple";

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.