[英]Getting the highest element from an array
I have a query which gives me a tuple of a discount added into database. 我有一个查询,它给了我添加到数据库的折扣元组。
Here's the query 这是查询
$discount_info = $this->autoload_model->get_data_from_table("td_discount,td_userdiscount","*",
"td_discount.discount_id = td_userdiscount.discount_id
AND td_discount.discount_code = '$coupon'")->result_array();
Now i have script which does the specific function. 现在我有执行特定功能的脚本。
There will be a condition, if the value of a index will be 1, then the code snippet is like this 会有一个条件,如果索引的值为1,则代码段如下所示
if($discount_info[0]['discount_on']=="3")
{
$discount_product = $discount_info[0]['discount_product']; // its an id(autoincrement value)//
if($discount_info[0]['applicable_type']==1)
{
$item_info = $this->autoload_model->get_data_From_table("td_product","*","product_id = '$discount_product'")->result_array();
foreach($this->cart->contents() as $ci)
{
if($ci['name'] = $item_info[0]['product_name']
{
// get the cart_item with the highest price if the product name matches//
}
}
}
}
My cart structure is like this 我的购物车结构是这样的
$data = array(
'id' => $id,
'qty' => $qty,
'price' => $price,
'name' => $name,
'options' => array(
'picture'=>$img,
'item_slug'=>$slug,
'item_color'=>$color,
'item_size'=>$size,
'unit_price'=>$price,
'order_type'=>$order_type,
'product_type'=>$pro_type,
'unit_discount' => 0.00,
'item_discount' => 0.00,
'discount_type' => '',
)
);
Now, its all set up, but I just can't get the login which I shall put over here 现在,所有设置均已完成,但我无法获得将在此处输入的登录信息
// get the cart_item with the highest price if the product name
I imagine you could just define a 我想您可以定义一个
$highest = array('price' => 0);
before the loop and then inside the loop go: 在循环之前,然后在循环内部进行:
// get the cart_item with the highest price if the product name matches//
if ($ci['price'] > $highest['price']) {
$highest = $ci;
}
That way $highest would contain the best match at the end. 这样最高的$会包含最后的最佳匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.