【发布时间】:2019-05-28 02:24:06
【问题描述】:
我有以下国家/地区数组($countryIso = array("US","BR","CL");),我的想法是创建一个新数组来显示以下架构:
('美国', 200)
我尝试创建以下结构:
$countryIso = array("US","BR","CL");
foreach ($countryIso as $isocode) {
$productcalc[] = "'" . strtoupper($isocode) . "'" . ',' . number_format($this->product->calculate($product = $product, $countryIso = $isocode), 0, '.', ',');
}
尽管我可以创建一个外观相似的格式,但我意识到该数组的格式不正确。当我检查输出显示以下内容:
数组 ( [0] => 'US',200
key 是 [0] 而不是 US。
关于如何使用
创建键 => 值结果的任何想法数组([美国] => 200
在我的代码中使用 foreach 结构?我尝试使用 array_combine 之类的变体将 countryIso 数组与 productcalc 数组结合,但没有成功
【问题讨论】:
-
$array['US'] = 200; -
$array[$isocode] = 200; -
array([$isocode],[$productcalc]) 显示 [1] => 数组 ( [0] => 数组 ( [0] => 'US',900 [1] => 'BR',1,215 [2] => 'CL',1,446 ) ) 但数组仍然 [0]
-
如果您要向问题添加信息。 请将其编辑到您的问题中
-
不确定这段代码应该做什么
calculate($product = $product, $countryIso = $isocode)