1
有什麼辦法可以避免在不使用循環的情況下創建重複對象名稱?避免在php中創建重複對象
$venue = array();
if(loop for checking duplicate OBJ){
$temp = some_var which fetch from database;
//If it's not a duplicate object, creates new object
$venue["$temp"] = new Venue($temp);
$venue["$temp"]->do something;
}
else{
//If it's a duplicate object, don't creates new object
$venue["$temp"]->do something;
}
我試圖用這樣的循環來檢查重複的對象名稱(「名稱」):
//檢查名稱是複製它在場地的陣列中的每個對象的?
for($itr = 0;$itr < $count($venue);$itr+=1){
if($venue["$temp"]->name === $name){
return true; //If it's a duplicate object name return true
}
}
問題是,當使用這個循環來檢查我,它消耗了大量的時間來完成這項工作
謝謝你,比我好 – 2014-11-23 14:47:39