2

我有数组:

$array = array(
  '/news/show/([0-9])/([0-9])'=>'/news/show/id/$1/id2/$2',
  '/home/ayz/([0-9])'=>'/home/xyz/sid/$1'
);

我想要结果:

$array = array(
      '/news/show/$1/$2'=>'/news/show/id/([0-9])/id2/([0-9])',
      '/home/ayz/$1'=>'/home/xyz/sid/([0-9])'
    );

怎么做??

4

1 回答 1

1
$aReplace = array('$1'=>'([0-9])','$2'=>'([0-9])');
$aNewArray = array();
foreach ($array as $key=>$value){
    $nKey = str_replace(array_values($aReplace),  array_keys($aReplace),$key);
    $nValue = str_replace(array_keys($aReplace),  array_values($aReplace),$value);
    $aNewArray[$nKey]=$nValue;
}
于 2013-08-28T19:24:21.213 回答