2 problems with array substitution OH
1.
How to put an array
Array (' 1234 ', ' 123 ');
Become
Array (' \ ' 1234\ ', ' \ ' 123\ ');
Such a
2.
$find = Array (' \ ' 1234\ ', ' \ ' 123\ ');
$shuju = Array (' 1234 ', ' 12345 ', ' 123456 ', ' 1234567 ', ' 123 ');
$tihuan = Array (' \ ' south wind \ ', ' \ ' westerly ');
$q = Str_replace ($find, $tihuan, Var_export ($shuju, true));
The output of this $q is an array (0=> Omitted:)
But the result I want is
South
12345
123456
1234567
Westerly
2 questions Oh, take a look for me, thank you
------Solution--------------------
1:
PHP Code
$arr =array (' 1234 ', ' 123 '), function foo ($p) {return "\ ' $p \ '";} $ar =array_map (' foo ', $arr);p Rint_r ($ar);
------Solution--------------------
Run results
Array (0 = ' South wind ', 1 = ' 12345 ', 2 = ' 123456 ', 3 = ' 1234567 ', 4 = ' westerly ',)
------Solution--------------------
1.
PHP Code
function foo ($v) {return "' $v '";} Print_r (Array_map (' foo ', Array (' 1234 ', ' 123 '));
------Solution--------------------
discuss
You're still not on Anta's request.
What he wants is a string substitution from the result of Var_export ($shuju, True)
In fact, his two questions are problematic.
------Solution--------------------
PHP Code
$shuju = Array (' 1234 ', ' 12345 ', ' 123456 ', ' 1234567 ', ' 123 ');//Raw Data foreach ($shuju as & $value)//Add quotation marks to each unit Value = "' $value '";//$shuju was modified already $find= array (' \ ' 1234\ ', ' \ ' 123\ '); $tihuan = Array (' \ ' southerly \ ', ' \ ' westerly ');//replaced by $q = str _replace ($find, $tihuan, $shuju), foreach ($q as $value) { echo substr ($value, 1,-1); echo "
\ n ";}
------Solution--------------------
PHP Code
$ar =array_combine ($find, $tihuan); function foo ($p) { global $ar; if ($ar [$p]) return $ar [$p]; else return $p;} foreach (Array_map (' foo ', $shuju) as $value) { echo $value; echo "