default keyword in php default keyword in php php php

default keyword in php


default is part of the switch statement:

switch ($cond) {  case 1:    echo '$cond==1';    break;  case 2:    echo '$cond==2';    break;  default:    echo '$cond=="whatever"';}


The default keyword is used in the switch construct:

$value = 'A';switch ($value) {case 'A':case 'B':    echo '$value is either A or B.';break;case 'C':    echo '$value is C.';break;default:    echo '$value is neither A, nor B, nor C.';}

The default case matches anything that wasn’t matched by the other cases.


Adding to others answers:

default is a PHP keyword and keywords cannot be used as function name.

When you try:

function default () { ....}

PHP expects to see a T_STRING ( an identifier) after the keyword function but sees a T_DEFAULT and flags a parse/syntax error:

unexpected T_DEFAULT, expecting T_STRING