我想遍历我的表,将列的值与数组值列表进行比较,这样如果匹配,我用数组键替换表中的值。 理想情况下,我可以这样做(搜索/替换),但我有很多价值观。所以我想将数组包含在inc文件中。
while($row = $db->fetchAssoc()){
$fields_count = 0;
foreach($row as $key => $val){
if($fields_count++ > 0)
$val = str_replace("Appliances > Air Conditioners","111,233", $val);
$val = str_replace("Appliances > Air Purifiers","154,234", $val);
$val = str_replace("Appliances > Appliance Accessories > Air Conditioner Accessories","123,235", $val);
这是我的数组和键,我如何完成循环,以便我可以在数组中搜索匹配的值并用表中的数组键替换它们?
$arr_categories = array(
"111,233"=>"Appliances > Air Conditioners",
"154,234"=>"Appliances > Air Purifiers",
"123,235"=>"Appliances > Appliance Accessories > Air Conditioner Accessories");
答案 0 :(得分:0)
$arrCategories = array(
'111,233' => 'Appliances > Air Conditioners',
'154,234' => 'Appliances > Air Purifiers',
'123,235' => 'Appliances > Appliance Accessories > Air Conditioner Accessories'
);
while ($row = $db->fetchAssoc()) {
foreach ($row as &$column) {
foreach ($arrCategories as $key => $category) {
$column = str_replace($category, $key, $column);
}
}
// Do something...
}