Coming from C# I must do a project in PHP.
I am using this code:
$transport = 'T';
$vehicle = (
( $transport == 'B' ) ? 'bus' :
( $transport == 'A' ) ? 'airplane' :
( $transport == 'T' ) ? 'train' :
( $transport == 'C' ) ? 'car' :
( $transport == 'H' ) ? 'horse' :
'feet' );
echo $vehicle;
I would expect it to print train, but I get horse. Codepad example: http://codepad.org/rWllfrht
Who can explain this strange behaviour?
I won’t advise you to use such code but for educational purposes it should be
A better code should be
Or better still:
Or, use a database: