<?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