var_dump($array);
給出:如何addslahes到多維數組值
Array
(
[data] => Array
(
[0] => Array
(
[name] => Mark O'Donel
[id] => 35802624
)
[1] => Array
(
[name] => Da's Messager
[id] => 522505962
)
)
)
任何想法如何斜線添加到數組中的值? 嘗試以下,但它不工作:
foreach($array as $list){
foreach($list as $elt){
$name = $elt['name'];
$id = $elt['id'];
echo 'before: '. $name .'<br><br>'; // Assuming $name= "Mark O'Donel"
$list[$id] = addslashes($name);
echo 'after: '. $elt['name'] .'<br><br>'; //suppose to give Mark O\'Donel
}
}
爲什麼你要和addslashes? – 2013-02-22 14:10:40
這個想法是有一個json編碼值。撇號的跡象似乎與創建問題json解析的值jquery – Lomse 2013-02-22 14:14:32
'json_encode'負責所有您需要的轉義... – knittl 2013-02-22 14:15:20