2017-02-24 8 views
0

は私がin_arrayで別のアレイに配列から要素を比較する必要が動作していない()メソッド:PHP PDOの比較が

$oldAttachedObjs = array();//this array need to be compare with single element of other loop  

$sqlObjAttached = "SELECT sno,ins_sno,obj_sno FROM cases_objections WHERE ins_sno = :ins_sno"; 
$paramObj = array(':ins_sno'=>$ins_sno); 

if($db->dbQuery($sqlObjAttached,$paramObj)){ 
    foreach($db->getRecordSet($sqlObjAttached,$paramObj) as $o){ 
     $oldAttachedObjs[] = $o; 
    }//foreach() 
} 

は、今私は、上記の配列の要素を比較したいです

Array ( 
    [0] => Array ([sno] => 1 [0] => 1 [ins_sno] => 2 [1] => 2 [obj_sno] => 3 [2] => 3), 
    [1] => Array ([sno] => 2 [0] => 2 [ins_sno] => 2 [1] => 2 [obj_sno] => 49 [2] => 49), 
    [2] => Array ([sno] => 3 [0] => 3 [ins_sno] => 2 [1] => 2 [obj_sno] => 52 [2] => 52), 
    [3] => Array ([sno] => 5 [0] => 5 [ins_sno] => 2 [1] => 2 [obj_sno] => 54 [2] => 54) 
) 
次のループ実際に

<?php 
    $sqlChildren = "SELECT sno,obj_sno,child_lbl FROM list_objection_children WHERE is_active = 1 AND obj_sno = :obj_sno ORDER BY sno ASC";          
    $param = array(':obj_sno'=>$obj['sno']);        

    if($db->dbQuery($sqlChildren,$param)){ 
     foreach($db->getRecordSet($sqlChildren,$param) as $ch){ 
?> 

<ul class="obj_ul"> 
    <li> 
     <div class="checkbox checkbox-primary"> 
     <?php print_r($oldAttachedObjs[0]); ?> 
      <input type="checkbox" <?php if(in_array($ch['sno'],$oldAttachedObjs['obj_sno'])){ ?> checked <?php //} ?> value="1" id="chk_<?php echo($ch['sno']);?>" name="chk_<?php echo($ch['sno']);?>" class="styled"> 
      <label style="font-weight: normal !important;" for="chk_<?php echo($ch['sno']);?>"><?php echo($ch['child_lbl']); ?></label> 
     </div> 
    </li> 
</ul> 

<?php 
     }//foreach() 
    } 
?> 

繰り返し処理ループ内の各要素には、以下の配列を移入します

しかし、配列は別の配列に含まれていて、私はこれで何をすべきか分からないので、比較するのは無理でしょうか?

+2

から得た結果の一つの内部にある '$のch'のですか? – gaurav

+0

または上記の配列$ oldAttachedObjsですか? – happymacarts

+0

$ oldAttachedObjsは上記の配列です。 –

答えて

1

内部配列と比較するために親配列をループする必要があります。あなたが探しているものは何でも天気ををチェックできるようになります

foreach($oldAttachedObjs as $objs){ 
    if(in_array('what you are looking for', $objs){ 
     //it is in the array, do what you want 
    }else{ 
     //it is not in the array, deal with it accordingly 
    } 
} 

この方法は、あなたが、アレイ上にデータベース

+0

はいこれが仕事です.... –

+0

嬉しいです!がんばろう! – FMashiro