$json=json_encode($_POST['myData']);
$decoded = json_decode($json,true);
if (is_array($decoded)) {
foreach ($decoded as $value) {
echo $value["name"] . "=" . $value["value"];
}
}
我为每个字段都有单独的值,我想要在数据库中存储单独的值..
发布是这样的:
myData[0][name] = name
myData[0][value] = Yaseen
myData[1][name] = age
myData[1][value] = 22
myData[2][name] = gender
myData[2][value] = male
myData[3][name] = skills
myData[3][value] = Php
myData[4][name] = note
myData[4][value] = sad
Please help...Thanks
var_dump()结果:
<br/>
array(1) { <br/>
["myData"]=><br/>
array(5) {<br/>
[0]=><br/>
array(2) {<br/>
["name"]=><br/>
string(4) "name"<br/>
["value"]=><br/>
string(6) "xyz"<br/>
}<br/>
[1]=><br/>
array(2) {<br/>
["name"]=><br/>
string(3) "age"<br/>
["value"]=><br/>
string(2) "22"<br/>
}<br/>
[2]=><br/><br/>
array(2) {<br/>
["name"]=><br/>
string(6) "gender"<br/>
["value"]=><br/>
string(4) "male"<br/>
}<br/>
[3]=><br/>
array(2) {<br/>
["name"]=><br/>
string(6) "skills"<br/><br/>
["value"]=><br/>
string(3) "Php"<br/>
}<br/>
[4]=><br/>
array(2) {<br/>
["name"]=><br/>
string(4) "note"<br/>
["value"]=><br/>
string(6) "asdasd"<br/>
}<br/>
}<br/>
}<br/>
答案 0 :(得分:0)
试
$json=json_encode($_POST['myData']);
$decoded = json_decode($json,true);
if (is_array($decoded)) {
for($i = 0; $i <= count($decoded); $i++) {
echo $decoded[$i]["name"];
}
}