Last Updated: February 25, 2016
· cleggypdc

Quick existance + length check on variables in PHP

Checking both the existance of a variable (no matter what depth in an object or array) and its length can be done in 1 line. Great for checking password lengths on a form for example:

     //password length check
     if(!isset($_POST['password']{5}) || !isset($_POST['password']{11}))
         echo 'Password must be between 6 - 12 characters';