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 result
Array (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 "
"; }