开发者

How to store MySql values as Multidimensional Array using PHP

I have a database table as follows.

<table border='1'><th>Id</th><th>FirstName</th><th>last Name</th><tr><td>1</td><td>Tom</td><td>T</td></tr><tr><td>2</td><td>Jerry</td><td>J</td></tr></table>

I would like to store all values as a multi dimensional array using php(using a while loop to retrieve fields).That is, I would like the data to be echoed as:

array(array(开发者_StackOverflow中文版1,Tom,T),array(2,Jerry,J));


$result = mysql_query("SELECT * FROM tablename;");
while($result_ar = mysql_fetch_array($result)) {
    $multid_array[] = $result_ar;
}

after which $multid_array will be an array of arrays.


You can use phps serialize function to convert any variable into a string representation

$string = serialize($dbData);

You can use unserialize() to convert the string back into arrays, objects, etc

$dbData = unserialize($string);

Once you have the data within a string, it's very easy to store in a file, db, etc. A disadvantage is that you won't be able to search your database easily for this data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜