如何将slahes添加到多维数组值中



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

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

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

相关内容

  • 没有找到相关文章

最新更新