Those parenthesis are what I think is getting you.
Try
$foo = 1;
$bar = ($foo == 1) ? "1" : (($foo == 2) ? "2" : "other");
echo $bar;
More Related Contents:
- Stacking Multiple Ternary Operators in PHP
- How to write a PHP ternary operator [duplicate]
- Ternary operator and string concatenation quirk?
- What is ?: in PHP 5.3? [duplicate]
- Ternary operator left associativity [duplicate]
- What does ? … : … do? [duplicate]
- Understanding nested PHP ternary operator [duplicate]
- PHP syntax question: What does the question mark and colon mean? [duplicate]
- C#’s null coalescing operator (??) in PHP
- PHP multiple ternary operator not working as expected
- Which coding style you use for ternary operator? [closed]
- Where can I read about conditionals done with “?” and “:” (colon)? [duplicate]
- Troubleshooting “Unexpected T_ECHO” in ternary operator statement
- How do you use bcrypt for hashing passwords in PHP?
- How to use cURL to get jSON data and decode the data?
- Why are my cookies not setting?
- PDO with INSERT INTO through prepared statements [closed]
- PHP threading call to a php function asynchronously
- Parsing JSON with PHP
- Seamless way to check if user likes page
- Unset a column in a multidimensional array
- Get all child, grandchild etc nodes under parent using php with mysql query results
- Dynamic shipping fee based on custom radio buttons in Woocommerce
- How to enable PHP’s openssl extension to install Composer?
- php multidimensional array get values
- PHP – Listing all directories and sub-directories recursively in drop down menu [duplicate]
- allow cross domain ajax requests
- Is there a way to get the list of available locales in PHP?
- Writing JSON object to .json file on server
- How to write html code inside block? [closed]