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 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法