如何使用 PHP 将 MySql 值存储为多维数组
我有一个数据库表如下。
<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>
我想使用 php 将所有值存储为多维数组(使用 while 循环来检索字段)。也就是说, 我希望数据被回显为:
array(array(1,Tom,T),array(2,Jerry,J));
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(1,Tom,T),array(2,Jerry,J));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用phps序列化函数将任何变量转换为字符串表示形式
您可以使用unserialize()将字符串转换回数组,对象等
一旦您在字符串中获得了数据,就可以很容易地将其存储在文件,数据库中等等。缺点是您无法轻松地在数据库中搜索这些数据。
You can use phps serialize function to convert any variable into a string representation
You can use unserialize() to convert the string back into arrays, objects, etc
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.
之后 $multid_array 将是一个数组的数组。
after which $multid_array will be an array of arrays.