时间:2021-07-01 10:21:17 帮助过:7人阅读
$arr=array('1234', '123'); function foo($p){ return "\'$p\'"; } $ar=array_map('foo',$arr); print_r($ar);
------解决方案--------------------
运行结果
array ( 0 => '南风', 1 => '12345', 2 => '123456', 3 => '1234567', 4 => '西风', )
------解决方案--------------------
1、
function foo($v) { return "'$v'"; } print_r(array_map('foo', array('1234', '123')));
------解决方案--------------------
$shuju= array ('1234','12345','123456','1234567','123');//原始数据 foreach($shuju as &$value) // 给每个单元两边加引号 $value = "'$value'"; // $shuju被修改了已经 $find= array('\'1234\'', '\'123\''); $tihuan= array('\'南风\'', '\'西风\'');//替换成的 $q = str_replace($find, $tihuan, $shuju); foreach($q as $value) { echo substr($value, 1, -1); echo "
\n"; }
------解决方案--------------------
$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 "
"; }