1

var_dump($array);给出:

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
    }
}
4

1 回答 1

0

更改后的值必须分配给数组变量:

foreach($array as $list){
    foreach($list as $index=>$elt){
       $name = $elt['name'];
       $id = $elt['id'];

       echo 'before: '. $name .'<br><br>'; // Assuming $name= "Mark O'Donel"
       $list[$index]['name'] = addslashes($name);
       echo 'after: '. $elt['name'] .'<br><br>'; //suppose to give Mark O\'Donel
    }
}
于 2013-02-22T14:12:59.660 回答