PHP-Code:
switch ($var) {
case null: echo 'es ist null'; break;
case 'b': echo 'es ist b'; break;
case array('c'): echo 'es ist [c]'; break;
case foo(): echo 'es ist foo()'; break;
}
switch ($var) {
case null: echo 'es ist null'; break;
case 'b': echo 'es ist b'; break;
case array('c'): echo 'es ist [c]'; break;
case foo(): echo 'es ist foo()'; break;
}
switch($var){
case 'hallo1':
case 'hallo2':
case 'hallo':
// do something
break;
}
<?php
for($j = 0; $j < 100; $j++) {
$start = microtime(true);
for($i = 0; $i < 100000; $i++) {
$var = 'hallo';
if($var === 'hallo1'
OR
$var === 'hallo2'
OR
$var === 'hallo'
) {
// do something
}
}
$end = microtime(true);
$or[] = $end-$start;
$start = microtime(true);
for($i = 0; $i < 100000; $i++) {
$var = 'hallo';
if(
in_array($var, array(
'hallo1',
'hallo2',
'hallo3'),
true)
) {
// do something
}
}
$end = microtime(true);
$inarray[] = $end-$start;
$start = microtime(true);
for($i = 0; $i < 100000; $i++) {
switch($var){
case 'hallo1':
case 'hallo2':
case 'hallo':
// do something
break;
}
}
$end = microtime(true);
$switch[] = $end-$start;
}
foreach($or as $value) {
$complete += $value;
}
echo "<pre>";
echo "Or: ". $complete / count($or);
echo "<br />";
$complete = 0;
foreach($inarray as $value) {
$complete += $value;
}
echo "In Array: ". $complete / count($inarray);
echo "<br />";
$complete = 0;
foreach($switch as $value) {
$complete += $value;
}
echo "Switch: ". $complete / count($switch);
echo "<br />";
?>
switch ( $exception ) {
case $exception instanceof actionNotFoundException:
case $exception instanceof entryNotFoundException:
...
break;
}
Kommentar