I have the following (simplified) code-fragment where I want to assign a value to variable $shell or $hole, depending on a certain condition ($ringIndex===1)
foreach($rings as $ringIndex=>$ring) { $polygon = $this->getPolygonFromRing($ring); if($ringIndex===1) { $shell = $polygon; } else { $hole = $polygon; } .... } I don't want to use an extra variable ($polygon) if it is not necessary
I thought maybe something like this would work:
foreach($rings as $ringIndex=>$ring) { ($ringIndex===1?$shell:$hole) = $this>getPolygonFromRing($ring); ... }