note 98052 added to language.operators.comparison

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
I am posting another hint about formatting of conditional expression blocks. It does take more lines, but lines starting with "?" and ":" allow to distinguish ternary operator quite quickly.

<?php
// Single ternary operator
$sentence = $value == 1
    ? 'You have one egg.'
    : 'You have '.$value.' eggs.';

// Nested ternary operators
$sentence = $value == 1
    ? 'You have one egg.'
    : ($value == 0
        ? 'You have no eggs.'
        ($value == 2
            ? 'You have two eggs.'
            : 'You have '.$value.' eggs.'
    );
?>

PS: In case on wondering about concatenation "." operator inside the expression: concatenation has higher priority than ternary operator, so it is evaluated first.
----
Server IP: 69.147.83.197
Probable Submitter: 89.24.95.254
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit        -- https://master.php.net/note/edit/98052
Del: integrated  -- https://master.php.net/note/delete/98052/integrated
Del: useless     -- https://master.php.net/note/delete/98052/useless
Del: bad code    -- https://master.php.net/note/delete/98052/bad+code
Del: spam        -- https://master.php.net/note/delete/98052/spam
Del: non-english -- https://master.php.net/note/delete/98052/non-english
Del: in docs     -- https://master.php.net/note/delete/98052/in+docs
Del: other reasons-- https://master.php.net/note/delete/98052
Reject      -- https://master.php.net/note/reject/98052
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.