<?php
$playerBox = json_decode($_POST['player_data'], true);
echo print_r($playerBox);
echo $playerBox['name'];
?>
我发送的数组由ajax到PHP,这是我的PHP代码,我的意图是获取每个值并为其创建一个html p。简单得到json_decode数组值,错误不知道
但我无法获得每个值,我不知道为什么每个人都可以使用它来获得它,我不能。
这里是print_r的
Array
(
[0] => Array
(
[id] => 1
[name] => Jonny
[number] => 27
)
[1] => Array
(
[id] => 2
[name] => dx
[number] => 28
)
)
的$ _ POST [ 'player_data')的错误我得到
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>(!)</span> Notice: Undefined index: name in C:\wamp\www\objecttest\directory\class-mail.php on line <i>7</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>135312</td><td bgcolor='#eeeeec'>{main}()</td><td title='C:\wamp\www\objecttest\directory\class-mail.php' bgcolor='#eeeeec'>..\class-mail.php<b>:</b>0</td></tr>
</table></font>
如何获得每个值,创建这样?
id name number
1 Johnny 27
2 dx 28
回声$ playerBox [0] [ '名称'];使用会得到正确的值 – JYoThI