Skip to content

Instantly share code, notes, and snippets.

@makoru-hikage
Last active February 18, 2017 01:45
Show Gist options
  • Save makoru-hikage/6f404f2133e1fa62ab004170b37c0f50 to your computer and use it in GitHub Desktop.
Save makoru-hikage/6f404f2133e1fa62ab004170b37c0f50 to your computer and use it in GitHub Desktop.
The correct use of switch case to test a variable's type. Correction for NullIsArray.php
<?php
$dummy= [
'Alpha' => null,
'Beta' => null,
'Charlie' => null
];
switch (gettype($dummy['Alpha'])) {
case 'array' :
echo 'Alpha, according to this switch statement, is Array';
break;
case 'double' :
case 'integer' :
echo 'Alpha, according to this switch statement, is Numeric';
break;
default:
echo 'Alpha, according to this switch statement, is something else';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment