我尝试使用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];
}
如何建立呢?
你为什么不使用你的查询连接上额外的查询发出了在初始每条记录的,而不是结果? –