dpli36193 2011-03-31 14:39
浏览 237
已采纳

将多维数组值存储到MySQL(PHP)中

I have a large multidimensional array that I would like to store into a MySQL database.

Below is an example of the array in question:

Array
(
    [user1] =>
        [name] => abc
        ...
        [address] => xyz
    ...
    ...
    [user2] =>
        [name] => abc
        ...
        [address] => xyz
}

The array values and database table columns all match (apart from the rowid in the database). I have seen various methods of doing something similar, but haven't found a way that works in this solution.

Many thanks :)

Update

Updated the array structure to give a clearer idea whats in the array itself.

  • 写回答

6条回答 默认 最新

  • dtup3446 2011-03-31 15:27
    关注

    In the end I took the time to use a for loop and achieve the following:

    for ($i = 0; $i < 25; $i++)
        {
            $name = $parts[$i][0];
            $address = $parts[$i][22];
    
            // Run SQL query using the variable values rather than the array values.
        }
    

    I'm sure there is a more sophisticated way of achieving this, but this worked for now!

    Thanks all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?