Multidimensional array recursion problem
PHP Code
In order to implement the contents of the removal of HTML a tag function Htmla (& $string) {if (Is_array ($string)) {foreach ($string as $ K=> $v) {$string [$k]=preg_replace ("/<\/?a.*?>/", "", $v); if (Is_array ($v)) {Htmla ($string [$k]); }}}else{$string =preg_replace ("/<\/?a.*?>/", "", $string); }} $test =array (1,2,34,5,array ("a" = "and", 1,23,array ("df" = "test"), Array (23,32)), "B" = "three"); HTMLA ($test); Var_dump ($test);//result Array (6) {[0] = = string (1) "1" [1] = = string (1) "2" [2] + string (2) "The" [3] = Stri Ng (1) "5" [4] = = Array (5) {["a"] + string (3) "and" [0] = string (1) "1" [1] = + string (2) "23" [2] = = String (5) "Array"//More than 2 dimensions cannot be converted. [3] = = string (5) "Array"} ["b"] = = string (3) "three"}
------Solution--------------------
foreach ($string as $k = $v)
{
$string [$k]=preg_replace ("/<\/?a.*?>/", "", $v);
if (Is_array ($v))
{
Htmla ($string [$k]);
}
Else
{
$string [$k]=preg_replace ("/<\/?a.*?>/", "", $v);
}
}