1){ foreach($temp as $str){ $code = $code.$str[0]; } $exist = ($type == "famplus") ? checkFamCodeExist(strtoupper($code)) : checkSFamCodeExist(strtoupper($code)); if($exist){ $lastid = ($type == "famplus") ? getFamLastId(strtoupper($code)) : getSFamLastId(strtoupper($code)); $count = ($lastid != null) ? intval($lastid['c']) : 0; $code = $code.($count + 1); $created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name)); if($created){ $exist = 0; } }else{ $created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name)); } }else{ $code = substr($name,0,3); $exist = ($type == "famplus") ? checkFamCodeExist(strtoupper($code)) : checkSFamCodeExist(strtoupper($code)); if($exist){ $lastid = ($type == "famplus") ? getFamLastId(strtoupper($code)) : getSFamLastId(strtoupper($code)); $count = ($lastid != null) ? intval($lastid['c']) : 0; $code = $code.($count + 1); $created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name)); }else{ $created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name)); } } } $data = array("exists" => $exist,"created"=>$created,"code"=>$code); echo json_encode($data); }