1

我一直在谷歌搜索和搜索这个论坛,但实际上我还没有找到我需要实现的解决方案。

我以这种形式从数据库中获取一个数组

Array
(
[0] => Array
    (
        [0] => af
        [1] => Afghanistan
    )

[1] => Array
    (
        [0] => al
        [1] => Algeria
    )
)

我需要它看起来像这样

Array
(
    [af] => Afghanistan
    [al] => Algeria
)

db 是 sql server,这是我用来获取数据的代码

$sQueryCountries = "SELECT Country_Code,Country_Name FROM Countries WHERE Client_Id = '$client_id'";
$params = array();
$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

$rResultCountries = sqlsrv_query( $db, $sQueryCountries, $params, $options );
while ( $aRow = sqlsrv_fetch_array( $rResultCountries, SQLSRV_FETCH_NUMERIC ) )
{       
    $output[] = $aRow;      
}
4

2 回答 2

4

在 fetch 循环中构建非常基本的数组

while ( $aRow = sqlsrv_fetch_array( $rResultCountries, SQLSRV_FETCH_NUMERIC ) )
{       
    $output[$aRow[0]] = $aRow[1];      
}
于 2013-03-05T11:29:41.367 回答
0

尝试这个 :

$res   = array();
foreach($your_array as $val){
   $res[$val[0]] = $val[1];
}

echo "<pre>";
print_r($res);
于 2013-03-05T11:31:54.590 回答