note 95896 deleted from control-structures.switch by crell

From: Date: Mon, 27 Jun 2022 21:56:38 +0000
Subject: note 95896 deleted from control-structures.switch by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218655@lists.php.net to get a copy of this message
Note Submitter: lchanady at gmail dot com ---- Something fairly simple (and maybe obvious) that I didn't see mentioned is that the default case WILL be executed even if the switched variable does not exist or is undefined. For example: <?php $a = "abc"; $b = "def"; switch($c){ case "a": echo "a"; break; case "b": echo "b"; break; default: echo "default"; break; } ?> Will output: default Even though $c was never declared or defined, the default case will still be executed rather than PHP throwing an error.

« previous php.notes (#218655) next »