Assigning variables by reference and ternary operator?
问题 Why ternary operator doesn't work with assignment by reference? $obj = new stdClass(); // Object to add $result = true; // Op result $success = array(); // Destination array for success $errors = array(); // Destination array for errors // Working $target = &$success; if(!$result) $target = &errors; array_push($target, $obj); // Not working $target = $result ? &$success : &$errors; array_push($target, $obj); 回答1: Here you go $target = ($result ? &$success : &$errors); Also your example has