如何在php数组中通过键更改值

时间:2015-01-17 08:34:18

标签: php arrays

我有以下数组:

array (
  'ID' => 'X485000CF',
  'TITLU' => 'xxxxxxxxxxxx,
  'APARTAMENTE' => 'Apartament',
  'GARS' => NULL,
  'VIL' => NULL,
  'SPA' => NULL,
  'INTRA' => NULL,
  'EXTRA' => NULL,

我想将密钥"APARTAMENTE"的值更改为"Cas/vil"

function timobil($str){
  $timobil1= array('APARTAMENTE' => 'Cas/vil');
  return strtr($str, $timobil1);
}

使用

将其打印在XML文档中
$identification->addChild('property_type', timobil($tip_proprietate));

1 个答案:

答案 0 :(得分:1)

$array=array (
 'ID' => 'X485000CF',
 'TITLU' => 'xxxxxxxxxxxx',
 'APARTAMENTE' => 'Apartament',
 'GARS' => NULL,
 'VIL' => NULL,
 'SPA' => NULL,
 'INTRA' => NULL,
 'EXTRA' => NULL);

$array['APARTAMENTE']='Cas/vil';

print_r($array);

现在将更新新阵列。