Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default keyword in php

Tags:

php

default

what does the keyword default in php do? there's no documentation on http://php.net/default, but i get an error when using it as a function name: »unexpected T_DEFAULT, expecting T_STRING«

what does it do/where can i find information about it?

like image 434
knittl Avatar asked Sep 05 '10 12:09

knittl


2 Answers

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"';
}
like image 116
bcosca Avatar answered Sep 19 '22 16:09

bcosca


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.

like image 39
Gumbo Avatar answered Sep 20 '22 16:09

Gumbo