Skip to content

Instantly share code, notes, and snippets.

@makoru-hikage
Last active February 18, 2017 01:01
Show Gist options
  • Save makoru-hikage/d3aadc400a1638c955e03bede678642b to your computer and use it in GitHub Desktop.
Save makoru-hikage/d3aadc400a1638c955e03bede678642b to your computer and use it in GitHub Desktop.
It seems that a `null` value is treated as an array()
<?php
$dummy= [
'Alpha' => null,
'Beta' => null,
'Charlie' => null
];
switch ($dummy['Alpha']) {
case is_array($dummy['Alpha']) :
echo 'gettype($dummy[\'Alpha\']) = '.gettype($dummy['Alpha'])."<br>";
echo 'is_array($dummy[\'Alpha\']) = '.is_array($dummy['Alpha'])."<br>";
echo 'Alpha, according to this switch statement, is Array';
break;
case is_numeric($dummy['Alpha']) :
echo 'gettype($dummy[\'Alpha\']) = '.gettype($dummy['Alpha'])."<br>";
echo 'is_array($dummy[\'Alpha\']) = '.is_array($dummy['Alpha'])."<br>";
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