开发者

Question on PHP Array Build

开发者 https://www.devze.com 2023-02-22 02:15 出处:网络
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.

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

精彩评论

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

关注公众号