【发布时间】:2018-05-14 15:13:56
【问题描述】:
我有一个如下所示的数组,我想要最小值,它是用于搜索税类 ID 的索引
Array
(
[tax_class_id] => Array
(
[0] => 12
[1] => 13
[2] => 13
)
[price] => Array
(
[0] => 6233
[1] => 3195
[2] => 19192
)
)
我正在 tax_class_id 中搜索最低价格和相应的键。在这个 Senario 中,我需要最低的价格,即 3195 和 tax_id - 13,即密钥 [1]
我的代码是
$prod_total = array();
for($i = 1;$i <= $chunk;$i++){
if($i == 1) {
$min_product_amt = min($product_amt['price']);
$index = array_search($min_product_amt, $product_amt);
$product_total = $min_product_amt;
//ceil Round numbers up to the nearest integer
$prod_total['price'] = ceil($product_total * $discount/100);
$prod_total['tax_id'] = $product_amt['tax_class_id'];
//Remove the first element from an array
array_shift($product_amt['price']);
array_shift($product_amt['tax_class_id']);
} else {
$second_min_product_amt = min($product_amt['price']);
$index = array_search($min_product_amt, $product_amt);
$product_total = $second_min_product_amt;
$prod_total['price'] = ceil($product_total * $discount/100);
$prod_total['tax_id'] = $product_amt['tax_class_id'];
array_shift($product_amt['price']);
array_shift($product_amt['tax_class_id']);
}
}
print_r($prod_total);
die;
【问题讨论】:
-
你能显示你需要什么输出吗?
-
从一个实际的问题/问题陈述开始怎么样?
-
你想解决什么问题?您的问题似乎与最小值和索引有关,但我在您的代码中看不到问题...
-
@rajkumar 没有一个答案适合您的需求?