下面是我正在使用的代码片段:
while(($response = $responses->fetchObject()) || ($mapping = $mappings->fetchObject())) {
$mapping = $mapping ? array('data' => array('#type'=>'link','#title' =>$mapping->title, '#href' => 'node/' . $mapping->nid)) : '';
$response = $response ? array('data' => array('#type'=>'link','#title' =>$response->title, '#href' => 'node/' . $response->nid)) : '';
}因为PHP会进行短路计算,所以即使$response执行,$mapping也不会被赋值。
我如何编写这段代码,以便在while循环中同时为$response和$mapping赋值?
发布于 2013-07-29 14:23:18
这是我现在的解决方案:
while(true) {
$response = $responses->fetchObject();
$mapping = $mappings->fetchObject();
if(!$response && !$mapping) {
break;
}
}但我觉得一定有更好的办法?
https://stackoverflow.com/questions/17917084
复制相似问题