rrylee
9/14/2015 - 2:57 PM

PHP Cookbook variable , function

PHP Cookbook variable , function

// You don't want to accidentally assign values when comparing a variable to a constant.
Use: 
  if (12 == $a) {}
instead of: 
  if ($a == 12) {}

// You want to assign a default value to a variable that doesn't already have a value.
$cars = isset($_GET['cars']) ? $_GET['cars'] : $default_cars;
$cars = array_key_exists('cars', $_GET) ? $_GET['cars'] : $default_cars;

# Function