# Questions about replacing two arrays

Source: Internet
Author: User
2. array replacement Problem 1. how to convert array ('123456', '123456') to array ('\ '000000',' \ '000000'); 2. \$ find = array ('\ '000000',' \ '000000'); \$ shuju = array ('000000', '000000 ')
1.
How to set the array
Array ('20140901', '20140901 ');
Change
Array ('\ '000000',' \ '000000 \'');
Such

2.
\$ Find = array ('\ '1234 \ '',' \ '123 \'');
\$ Shuju = array ('20140901', '20160901', '20160301', '20160301 ');
\$ Tihuan = array ('\ 'southwind \ '',' \ 'West wind \'');
\$ Q = str_replace (\$ find, \$ tihuan, var_export (\$ shuju, true ));
The \$ q output is array (0 =>... omitted ..)

But what I want is
Nanfeng
12345
123456
1234567
West Wind

Two questions. let's take a look. thank you.

------ Solution --------------------
1:
PHP code
```\$ Arr = array ('20140901', '20160901'); function foo (\$ p) {return "\ '\$ p \'";} \$ ar = array_map ('foo', \$ arr); print_r (\$ ar );------ Solution --------------------Running resultArray (0 => 'southwind ', 1 => '000000', 2 => '000000', 3 => '000000', 4 => 'West ',)------ Solution --------------------1,

PHP code

Function foo (\$ v) {return "'\$ V'";} print_r (array_map ('foo', array ('20140901', '20140901 ')));------ Solution --------------------

Discussion

You still do not have Anta's requirements.
He wants to replace the string from the result of var_export (\$ shuju, true ).

In fact, both of his questions are problematic.

------ Solution --------------------

PHP code

\$ Shuju = array ('20160301', '20160301', '20160301', '20160301'); // raw data foreach (\$ shuju as & \$ value) // quote \$ value = "'\$ value'" on both sides of each unit; // \$ shuju has been changed to \$ find = array (' \ '2017 \'', '\ '2014 \ ''); \$ tihuan = array (' \ 'southwind \'', '\ 'westwind \''); // replace with \$ 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 ""; }

```
Related Keywords:

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.