這是JavaScript代碼,如何將PHP數組數據錶轉換爲javascript?
var tabledata = [
\t {id:1, name:"Oli Bob", age:"12", gender:"male", height:1, col:"red", dob:"", cheese:1, lucky_no:5},
\t {id:2, name:"Mary May", age:"1", gender:"female", height:2, col:"blue", dob:"14/05/1982", cheese:true, lucky_no:10},
\t {id:3, name:"Christine Lobowski", age:"42", height:0, col:"green", dob:"22/05/1982", cheese:"true", lucky_no:12},
\t {id:4, name:"Brendon Philips", age:"125", gender:"male", height:1, col:"orange", dob:"01/08/1980", lucky_no:18},
\t {id:5, name:"Margret Marmajuke", age:"16", gender:"female", height:5, col:"yellow", dob:"31/01/1999", lucky_no:33},
\t {id:6, name:"Frank Harbours", age:"38", gender:"male", height:4, col:"red", dob:"", cheese:1, lucky_no:2},
\t {id:7, name:"Jamie Newhart", age:"23", gender:"male", height:3, col:"green", dob:"14/05/1985", cheese:true, lucky_no:63},
\t {id:8, name:"Gemma Jane", age:"60", height:0, col:"red", dob:"22/05/1982", cheese:"true", lucky_no:72},
\t {id:9, name:"Emily Sykes", age:"42", gender:"female", height:1, col:"maroon", dob:"11/11/1970", lucky_no:44},
\t {id:10, name:"James Newman", age:"73", gender:"male", height:5, col:"red", dob:"22/03/1998", lucky_no:9},
];
this is my php code :
<?php $arr1 = array (
array('id'=>'1', 'name'=>'Oli Bob','age'=>'12', 'gender'=>'male','height'=>'1','col'=>'red','dob'=>'', 'cheese'=>'1','lucky_no'=>'5'),
array('id'=>'2', 'name'=>'Mary May','age'=>'1', 'gender'=>'female','height'=>'2','col'=>'blue','dob'=>'14/05/1982', 'cheese'=>'true','lucky_no'=>'10')
);?>
and javascript :
var tabledata = "<?php json_encode($arr1);?>";
Please Help...? :(
我qustion是,在PHP代碼的JavaScript可能錯誤的,我嘗試..! JavaScript代碼是像我的第一篇文章一樣的固定代碼。
正確答案是,「這取決於」。 –
我已經改變了他們的伴侶,請檢查他們。謝謝 – Mike