【发布时间】:2017-11-29 19:43:14
【问题描述】:
我有以下(简化的)代码片段,我想根据特定条件为变量 $shell 或 $hole 赋值($ringIndex===1)
foreach($rings as $ringIndex=>$ring) {
$polygon = $this->getPolygonFromRing($ring);
if($ringIndex===1) {
$shell = $polygon;
} else {
$hole = $polygon;
}
....
}
如果没有必要,我不想使用额外的变量 ($polygon)
我想也许这样的事情会起作用:
foreach($rings as $ringIndex=>$ring) {
($ringIndex===1?$shell:$hole) = $this>getPolygonFromRing($ring);
...
}
【问题讨论】:
标签: php conditional assign