2 questions about array substitution Oh, yes.

Source: Internet
Author: User
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 "
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.