开发者

array_key_exist on first layer of multidimensional array

Can somebody tell my why the following code doesn't work?

$ReturnData=array(
    'cardauth'=>array('success'=>'')
);

$Query="SELECT cardauth FROM y WHERE x = '".$x."'";
$Data=mysql_query($Query);
while($Row = mysql_fetch_array($Data)){
    foreach($Row as $k => $v){
        if(array_key_exists($k,$ReturnData)){
            $ReturnData[$k]['success']=$v;
        }
    }
}
die(print_r($ReturnData));

I'm trying to set the values of the second dimension of the array $ReturnData with the column that is being crossed by the mysql fetch. 'cardauth'开发者_Python百科 will be a BIT. I use the same method to populate single dimension arrays inside of the same loop. I've removed all the unnecessary code.

array_key_exists is not working. $ReturnData['cardauth']['success'] is not being set to the value of the column.


Use else to solve your problem! This else could be:

} else  {
  printf("array_key_exists did return true because [%s] does not contain %s",
    implode(array_keys($ReturnData), ', '), 
    $k);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜