以二维方式转换数组

时间:2013-08-09 05:54:31

标签: php mysql

我将此结果作为mysql_fetch_row函数返回数据库中的行...

Array
(
    [firstname] => abc
    [lastname] => xyz
    [password] => abc
    [gender] => female
    [city] => malborne
    [email] => abc@gmail.com
    [address] => abc
)

我希望这个数组为

Array
(
  [0] array(


        [firstname] => abc
        [lastname] => xyz
        [password] => abc
        [gender] => female
        [city] => malborne
        [email] => abc@gmail.com
        [address] => abc

)
)

3 个答案:

答案 0 :(得分:1)

$newArray = array($data);
print_r($newArray);

输出:

Array
(
    [0] => Array
        (
            [firstname] => abc
            [lastname] => xyz
            [password] => abc
            [gender] => female
            [city] => malborne
            [email] => abc@gmail.com
            [address] => abc
        )

)

Ta-dah!

答案 1 :(得分:0)

这很容易,您可以通过将其插入另一个数组

来创建所需的结构
$original = array(.....);
$final = array($original);

答案 2 :(得分:0)

$myArray = array();

while($row = mysql_fetch_row(...)) {
  $myArray[] = $row;
}
// $myArray is your final array