dongre6404 2015-07-10 10:36
浏览 48
已采纳

如何在打开的购物车中比较数组中特定索引的值

i have an array $ results, which gives me following output when i do print_r on it.

Array ( 
    [0] => Array ( 
        [parent_geo_zone_id] => 3 
        [name] => UK VAT Zone 
        [shipping_pool_geo_zone_id] => 
        [email] => 
    ) 
    [1] => Array ( 
        [parent_geo_zone_id] => 4 
        [name] => UK Shipping 
        [shipping_pool_geo_zone_id] => 
        [email] => 
    ) 
    [2] => Array ( 
        [parent_geo_zone_id] => 5 
        [name] => Texas 
        [shipping_pool_geo_zone_id] => 5 
        [email] => ammar.instantsoft@gmail.com 
    ) 
    [3] => Array ( 
        [parent_geo_zone_id] => 6 
        [name] => florida 
        [shipping_pool_geo_zone_id] => 6 
        [email] => ammar_ul_hasan@hotmail.com 
    ) 
    [4] => Array ( 
        [parent_geo_zone_id] => 7 
        [name] => alaska 
        [shipping_pool_geo_zone_id] => 
        [email] => 
    ) 
)

I want to compare the following indexes

'parent_geo_zone_id' and 'shipping_pool_geo_zone_id ' 

like this

if($results->array['parent_geo_zone_id']==$results->array['shipping_pool_geo_zone_id '])

where ever these two ids are equal i want to send my checkbox value as checked to view other wise unchecked like this.

 foreach ($results as $result) {

            $this->data['geo_zones'][] = array(
                'geo_zone_id' => $result['parent_geo_zone_id'],
                'name'        => $result['name'],
                'email'       => $result['email'],

                'selected'    => isset($this->request->post['selected']) && in_array($result['geo_zone_id'], $this->request->post['selected'])

            );

I am using open cart.

  • 写回答

1条回答 默认 最新

  • douduoquan2824 2015-07-10 11:19
    关注

    You just can use such expression

    if($result['parent_geo_zone_id'] === $result['shipping_pool_geo_zone_id'])
      {
      // any stuff for true
      } 
    else
      {
      // any stuff for false
      } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看