开发者

Question on PHP Array Build

I want to build an array based on MySQL query result.

assume dbArrA and dbArrB c开发者_StackOverflowome from db query result. And they are both arrais.

dbArrA = (1, 2, 4, 5);
dbArrB = (A, B, D, E);

How can I build the $data as this, thanks.

    $data = array(
            1  => 'A',
            2  => 'B',
            4 => 'D',
            5 => 'E'

    );


try

array_combine($dbArrA,$dbArrB)

Reference:

array_combine


Use array_combine():

$result = array_combine($dbArrA, $dbArrB);


Something like this?

$data = array();
foreach($dbArrA as $key=>$value){
  $data[$value] = $dbArrB[$key];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜