2017-03-17 122 views
-1

我檢查標籤,如果它存在的標籤應該存在但隨後轉到存在和不存在的條件,這是我的代碼:傳遞函數變量

function _checkTagsExists($tag , $chimptags){ 

foreach($chimptags as $key => $value){ 

    if($value == $tag){ 
    $response[ 'value' ] = $value; 
    $response[ 'exists' ] = 1; 
    $response[ 'tag' ] = $tag; 
    $response[ 'interests_id' ] = $key; 
    } 

} 
return $response; 
} 
$actags = array('existingtag1','existingtag2'); 
$interests = array('key1'=>'existingtag1','key2'=>'existingtag2'); 
foreach($actags as $actag){ 

     $tagscheck = _checkTagsExists($actag , $interests); 


     //if tag is already existing 
     if($tagscheck[ 'exists' ] == 1){ 

     $message[] = "exists"; 


     }else{ 
     $message[] = "NOT exist"; 


     } 
} 
var_dump($message); 

該代碼產生

array{0 => "exists", 1 => "NOT exist"} 

但它應該是所有存在

+2

你應該改寫你的問題,因爲它實際上很難理解。 –

+0

我剛剛運行你的代碼,它的工作原理:array(2){[0] => string(6)「exists」[1] => string(6)「exists」} – Neil

+0

OMG是啊我也試過了,我需要更改代碼,因爲我只是使用簡單的數組 – Andrei

回答

0

通過增加在循環中斷解決了這個,如果標籤被發現,這樣就不會再次向陣列的其他價值