我嘗試使用foreach循環更新數組中的值。然後用更新的值打印數組。我在這裏發佈我的當前代碼。請回復示例代碼。感謝您。 這裏是我的數組:如何通過循環更新數組中的值
[associated_branch] => Array
(
[0] => Array
(
[store_id] => 0
[store_name] => Bazar Kolkata
[location] => Array
(
[location] => Sonarpur
)
[address_line1] => J L N Road
[address_line2] => Kolkata
[city] => 4
[state] => 24
)
[1] => Array
(
[store_id] => 16
[store_name] => KC DAS
[location] => Array
(
[location] => Garia Hat
)
[address_line1] => kolkata
[address_line2] =>
[city] => 4
[state] => 24
)
)
,我想:
[associated_branch] => Array
(
[0] => Array
(
[store_id] => 0
[store_name] => Bazar Kolkata
[location] => Sonarpur
[address_line1] => J L N Road
[address_line2] => Kolkata
[city] => 4
[state] => 24
)
[1] => Array
(
[store_id] => 16
[store_name] => KC DAS
[location] => Garia Hat
[address_line1] => kolkata
[address_line2] =>
[city] => 4
[state] => 24
)
)
我的SQL:
$assoBrSql="SELECT store_id, store_name, location, address_line1, address_line2, city, state FROM ".DB_MY_PREFIX."my_web_stores WHERE store_id IN($row[branch_ids]) AND cur_status=1 && is_more_branch =1 AND associated_branch IS NOT NULL";
$branches = $db->ExecuteQuery($assoBrSql);
$row['associated_branch']=$branches;
foreach ($row['associated_branch'] as $key => $value) {
$locsql="SELECT location FROM " .DB_MY_PREFIX. "my_localities WHERE location_id='".$value['location']."'";
$locrows=$db->ExecuteQuery($locsql);
$row['associated_branch'][$key]['location']=$locrows[0];
}
如何建立呢?
你爲什麼不使用你的查詢連接上額外的查詢發出了在初始每條記錄的,而不是結果? –