Home >Backend Development >PHP Tutorial >二维数组储存至数据库有关问题

二维数组储存至数据库有关问题

WBOY
WBOYOriginal
2016-06-13 10:35:281185browse

二维数组储存至数据库问题
我想将一个二维的数组的值储存到mysql数据库中不知如何做,例:
字段:name age sex
数组:array(array(sh,20,男),array(se,30,女));

------解决方案--------------------
serialize()

序列化.

 使用的时候还原一下
unserialize()
------解决方案--------------------
$ar = array(array('sh',20,'男'),array('se',30,'女'));
foreach($ar as $v) {
mysql_query("insert into 表 (name, age, sex) values ('$v[0]', $v[1], '$v[2]')");
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn