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:
<?php
//password length check
if(!isset($_POST['password']{5}) || !isset($_POST['password']{11}))
{
echo 'Password must be between 6 - 12 characters';
}
?>
Written by Paul Clegg
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#