2017-03-17 152 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

通过增加在循环中断解决了这个,如果标签被发现,这样就不会再次向阵列的其他价值