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];
}
精彩评论