array_map and htmlentities

核能气质少年 提交于 2019-12-04 12:41:39

Because $lang is a two dimensional array, so it won't work

For two dimensional array you need to use for loop

foreach($$lang as &$l):
    $l = array_map('htmlentities', $l);
}

Use array_walk_recursive. array_map doesn't work with multidimensional arrays:

array_walk_recursive($lang, function (&$value) {
    $value = htmlentities($value);
});

$lang['var_char1']['varchar2'] defines a multidimensional array, so each element of $lang is also an array. array_map() iterates through $lang, passing an array to htmlentities() instead of a string.

array_map() doesn't work recursively. If you know your array is always two levels deep you could loop through it and use array_map on the sub-arrays.

Refnaldi Hakim

if you like quotes


function stripslashes_array(&$arr) {
    array_walk_recursive($arr, function (&$val) {
        $val = htmlentities($val, ENT_QUOTES);
    });
}

multiple array in post, get, dll

stripslashes_array($_POST);

stripslashes_array($_GET);

stripslashes_array($_REQUEST);

stripslashes_array($_COOKIE);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!