php - ternary operator with ampersand -


this question has answer here:

i use followed somewhere in code:

if (isset($flat[$pid])) {   $branch = &$flat[$pid]['items']; } else {   $branch = &$tree; }     

all ok, when want short to:

$branch = isset($flat[$pid]) ? &$flat[$pid]['items'] : &$tree; 

i get:

syntax error, unexpected '&' ...

what i'm doing wrong?

this because ternary operator expression, doesn't evaluate variable. , quote manual:

note: please note ternary operator expression, , doesn't evaluate variable, result of expression. important know if want return variable reference. statement return $var == 42 ? $a : $b; in return-by-reference function therefore not work , warning issued in later php versions.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -