从多维数组PHP HTTP输出信息

时间:2017-12-07 17:21:18

标签: php arrays

我正在尝试根据所有数组中的rim_diameter获得rim_offset和rim_width的 Min Max 值。

阵列数量各不相同。

例如。如果rim_diameter为17,则rim_width min 为:“”和 max rim_width为:“”

或列出rim_width和rim_offset的所有值,如下所示: 31,32,33例如。 rim_diameter 17

此代码仅用于在其中一个数组中获取rim_diameter:

$Rimdiameter = $data[0]['wheels'][1]['front']['rim_diameter'] . ',' . $data[0]['wheels'][1]['rear']['rim_diameter']; 

如何获取rim_diameter的rim_width和rim_offset的值(当rim_diameter值在不同的子数组中相同时)?

使用var dump

更新
   Var_dump:


 array(9) {
 [0]=>
 array(4) {
 ["showing_fp_only"]=>
bool(true)
["is_stock"]=>
bool(true)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(220)
    ["psi"]=>
    float(32)
    ["bar"]=>
    float(2.2)
  }
  ["rim"]=>
  string(10) "7Jx16 ET31"
  ["rim_diameter"]=>
  float(16)
  ["rim_width"]=>
  float(7)
  ["rim_offset"]=>
  float(31)
  ["tire"]=>
  string(9) "205/55R16"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(205)
  ["tire_aspect_ratio"]=>
  float(55)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(91)
  ["speed_index"]=>
  string(1) "V"
 }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(260)
    ["psi"]=>
    float(38)
    ["bar"]=>
    float(2.6)
  }
  ["rim"]=>
  string(0) ""
  ["rim_diameter"]=>
  NULL
  ["rim_width"]=>
  NULL
  ["rim_offset"]=>
  NULL
  ["tire"]=>
  string(0) ""
  ["tire_sizing_system"]=>
  NULL
  ["tire_construction"]=>
  NULL
  ["tire_width"]=>
  NULL
  ["tire_aspect_ratio"]=>
  NULL
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  NULL
  ["speed_index"]=>
  NULL
}
}
[1]=>
array(4) {
["showing_fp_only"]=>
bool(true)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(220)
    ["psi"]=>
    float(32)
    ["bar"]=>
    float(2.2)
  }
  ["rim"]=>
  string(10) "7Jx16 ET31"
  ["rim_diameter"]=>
  float(16)
  ["rim_width"]=>
  float(7)
  ["rim_offset"]=>
  float(31)
  ["tire"]=>
  string(9) "205/55R16"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(205)
  ["tire_aspect_ratio"]=>
  float(55)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(91)
  ["speed_index"]=>
  string(1) "H"
  }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(260)
    ["psi"]=>
    float(38)
    ["bar"]=>
    float(2.6)
   }
   ["rim"]=>
  string(0) ""
  ["rim_diameter"]=>
  NULL
  ["rim_width"]=>
  NULL
  ["rim_offset"]=>
  NULL
  ["tire"]=>
  string(0) ""
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  NULL
  ["tire_aspect_ratio"]=>
  NULL
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  NULL
  ["speed_index"]=>
  NULL
 }
 }
 [2]=>
array(4) {
["showing_fp_only"]=>
bool(true)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(220)
    ["psi"]=>
    float(32)
    ["bar"]=>
    float(2.2)
  }
  ["rim"]=>
  string(10) "7Jx16 ET34"
  ["rim_diameter"]=>
  float(16)
  ["rim_width"]=>
  float(7)
  ["rim_offset"]=>
  float(34)
  ["tire"]=>
  string(9) "205/55R16"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(205)
  ["tire_aspect_ratio"]=>
  float(55)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(91)
  ["speed_index"]=>
  string(1) "V"
 }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(260)
    ["psi"]=>
    float(38)
    ["bar"]=>
    float(2.6)
  }
  ["rim"]=>
  string(0) ""
  ["rim_diameter"]=>
  NULL
  ["rim_width"]=>
  NULL
  ["rim_offset"]=>
  NULL
  ["tire"]=>
  string(0) ""
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  NULL
  ["tire_aspect_ratio"]=>
  NULL
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  NULL
  ["speed_index"]=>
  NULL
}
}
[3]=>
array(4) {
["showing_fp_only"]=>
bool(true)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(220)
    ["psi"]=>
    float(32)
    ["bar"]=>
    float(2.2)
  }
  ["rim"]=>
  string(10) "7Jx16 ET34"
  ["rim_diameter"]=>
  float(16)
  ["rim_width"]=>
  float(7)
  ["rim_offset"]=>
  float(34)
  ["tire"]=>
  string(10) "225/50ZR16"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(225)
  ["tire_aspect_ratio"]=>
  float(50)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(92)
  ["speed_index"]=>
  string(1) "Y"
 }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(260)
    ["psi"]=>
    float(38)
    ["bar"]=>
    float(2.6)
  }
  ["rim"]=>
  string(0) ""
  ["rim_diameter"]=>
  NULL
  ["rim_width"]=>
  NULL
  ["rim_offset"]=>
  NULL
  ["tire"]=>
  string(0) ""
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  NULL
  ["tire_aspect_ratio"]=>
  NULL
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  NULL
  ["speed_index"]=>
  NULL
}
}
[4]=>
array(4) {
["showing_fp_only"]=>
bool(true)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(220)
    ["psi"]=>
    float(32)
    ["bar"]=>
    float(2.2)
  }
  ["rim"]=>
  string(10) "8Jx17 ET34"
  ["rim_diameter"]=>
  float(17)
  ["rim_width"]=>
  float(8)
  ["rim_offset"]=>
  float(34)
  ["tire"]=>
  string(9) "225/45R17"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(225)
  ["tire_aspect_ratio"]=>
  float(45)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(91)
  ["speed_index"]=>
  string(1) "H"
  }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(260)
    ["psi"]=>
    float(38)
    ["bar"]=>
    float(2.6)
  }
  ["rim"]=>
  string(0) ""
  ["rim_diameter"]=>
  NULL
  ["rim_width"]=>
  NULL
  ["rim_offset"]=>
  NULL
  ["tire"]=>
  string(0) ""
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  NULL
  ["tire_aspect_ratio"]=>
  NULL
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  NULL
  ["speed_index"]=>
  NULL
 }
}
[5]=>
array(4) {
["showing_fp_only"]=>
bool(true)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(220)
    ["psi"]=>
    float(32)
    ["bar"]=>
    float(2.2)
  }
  ["rim"]=>
  string(10) "8Jx17 ET34"
  ["rim_diameter"]=>
  float(17)
  ["rim_width"]=>
  float(8)
  ["rim_offset"]=>
  float(34)
  ["tire"]=>
  string(10) "225/45ZR17"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(225)
  ["tire_aspect_ratio"]=>
  float(45)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(91)
  ["speed_index"]=>
  string(1) "Y"
 }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(260)
    ["psi"]=>
    float(38)
    ["bar"]=>
    float(2.6)
  }
  ["rim"]=>
  string(0) ""
  ["rim_diameter"]=>
  NULL
  ["rim_width"]=>
  NULL
  ["rim_offset"]=>
  NULL
  ["tire"]=>
  string(0) ""
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  NULL
  ["tire_aspect_ratio"]=>
  NULL
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  NULL
  ["speed_index"]=>
  NULL
 }
}
[6]=>
array(4) {
["showing_fp_only"]=>
bool(false)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(220)
    ["psi"]=>
    float(32)
    ["bar"]=>
    float(2.2)
  }
  ["rim"]=>
  string(10) "8Jx17 ET34"
  ["rim_diameter"]=>
  float(17)
  ["rim_width"]=>
  float(8)
  ["rim_offset"]=>
  float(34)
  ["tire"]=>
  string(10) "225/45ZR17"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(225)
  ["tire_aspect_ratio"]=>
  float(45)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(91)
  ["speed_index"]=>
  string(1) "Y"
 }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(260)
    ["psi"]=>
    float(38)
    ["bar"]=>
    float(2.6)
  }
  ["rim"]=>
  string(12) "8.5Jx17 ET37"
  ["rim_diameter"]=>
  float(17)
  ["rim_width"]=>
  float(8.5)
  ["rim_offset"]=>
  float(37)
  ["tire"]=>
  string(10) "255/40ZR17"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(255)
  ["tire_aspect_ratio"]=>
  float(40)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(94)
  ["speed_index"]=>
  string(1) "Y"
 }
 }
 [7]=>
array(4) {
["showing_fp_only"]=>
bool(false)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(210)
    ["psi"]=>
    float(30)
    ["bar"]=>
    float(2.1)
  }
  ["rim"]=>
  string(10) "8Jx18 ET34"
  ["rim_diameter"]=>
  float(18)
  ["rim_width"]=>
  float(8)
  ["rim_offset"]=>
  float(34)
  ["tire"]=>
  string(10) "225/40ZR18"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(225)
  ["tire_aspect_ratio"]=>
  float(40)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(88)
  ["speed_index"]=>
  string(1) "Y"
 }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(240)
    ["psi"]=>
    float(35)
    ["bar"]=>
    float(2.4)
  }
  ["rim"]=>
  string(12) "8.5Jx18 ET37"
  ["rim_diameter"]=>
  float(18)
  ["rim_width"]=>
  float(8.5)
  ["rim_offset"]=>
  float(37)
  ["tire"]=>
  string(10) "255/35ZR18"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(255)
  ["tire_aspect_ratio"]=>
  float(35)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(90)
  ["speed_index"]=>
  string(1) "Y"
}
}
[8]=>
&array(4) {
["showing_fp_only"]=>
bool(false)
["is_stock"]=>
bool(false)
["front"]=>
array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(210)
    ["psi"]=>
    float(30)
    ["bar"]=>
    float(2.1)
  }
  ["rim"]=>
  string(10) "8Jx19 ET37"
  ["rim_diameter"]=>
  float(19)
  ["rim_width"]=>
  float(8)
  ["rim_offset"]=>
  float(37)
  ["tire"]=>
  string(10) "225/35ZR19"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(225)
  ["tire_aspect_ratio"]=>
  float(35)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(88)
  ["speed_index"]=>
  string(1) "Y"
 }
 ["rear"]=>
 array(15) {
  ["tire_pressure"]=>
  array(3) {
    ["kPa"]=>
    float(240)
    ["psi"]=>
    float(35)
    ["bar"]=>
    float(2.4)
  }
  ["rim"]=>
  string(10) "9Jx19 ET39"
  ["rim_diameter"]=>
  float(19)
  ["rim_width"]=>
  float(9)
  ["rim_offset"]=>
  float(39)
  ["tire"]=>
  string(10) "255/30ZR19"
  ["tire_sizing_system"]=>
  string(6) "metric"
  ["tire_construction"]=>
  string(1) "R"
  ["tire_width"]=>
  float(255)
  ["tire_aspect_ratio"]=>
  float(30)
  ["tire_diameter"]=>
  NULL
  ["tire_section_width"]=>
  NULL
  ["tire_is_82series"]=>
  bool(false)
  ["load_index"]=>
  int(91)
  ["speed_index"]=>
  string(1) "Y"
}
}

1 个答案:

答案 0 :(得分:0)

foreach ($data[0]['wheels'] as &$value) {

$diameterF = $value['front']['rim_diameter'];
$diameterR = $value['rear']['rim_diameter'];
$felgbreddeF = $value['front']['rim_width'];
$felgbreddeR = $value['rear']['rim_width'];
$boltsirkel = $data[0]['bolt_pattern'];
$navdim = $data[0]['centre_bore'];
$gjengetype = $data[0]['lock_type'];
$gjengetext = $data[0]['lock_text'];
$gjenger = $norskgjtext .' ' .$gjengetext;
$norskgjtext = str_replace('nut','mutter',$gjengetype);
$dekkbreddeF = $value['front']['tire_width'];
$dekkbreddeR = $value['rear']['tire_width'];
$dekkprofilF = $value['front']['tire_aspect_ratio'];
$dekkprofilR = $value['rear']['tire_aspect_ratio'];

$rimoffsetFmax[$diameterF] = $value['front']['rim_offset'];
$rimoffsetRmax[$diameterR] = $value['rear']['rim_offset'];
$rimoffsetFmin[$diameterF] = $value['front']['rim_offset'];
$rimoffsetRmin[$diameterR] = $value['rear']['rim_offset'];

//Finn max og min verdier for innpress,dekkbredde,dekkprofil//
$maxinnpressF = max(array_filter($rimoffsetFmax));
$maxinnpressR = max(array_filter($rimoffsetRmax));
$mininnpressF = min(array_filter($rimoffsetFmin));
$mininnpressR = min(array_filter($rimoffsetRmin));

 if ($maxinnpressF > $maxinnpressR) {
 $maxET = $maxinnpressF;
 }else {
 $maxET = $maxinnpressR;}


 if ($mininnpressF < $mininnpressR) {
 $minET = $mininnpressF;
 }else {
 $minET = $mininnpressR;
 }

 if (in_array("NULL", $dekkbreddeF)) {
 $dekkbreddeR = $dekkbreddeF;
 }
 $array[$diameterF]['MAX-ET'] = ($maxET);
 $array[$diameterR]['MAX-ET'] = ($maxET);
 $array[$diameterF]['MIN-ET'] = ($minET);
 $array[$diameterR]['MIN-ET'] = ($minET);
 $array[$diameterF]['Felgbredde'] = ($felgbreddeF .','.$felgbreddeR);
 $array[$diameterR]['Felgbredde'] = ($felgbreddeF .','.$felgbreddeR);
 $array[$diameterF]['Boltsirkel'] = ($boltsirkel);
 $array[$diameterR]['Boltsirkel'] = ($boltsirkel);
 $array[$diameterF]['Navdiameter'] = ($navdim);
 $array[$diameterR]['Navdiameter'] = ($navdim);
 $array[$diameterF]['Gjengetype'] = ($gjenger);
 $array[$diameterR]['Gjengetype'] = ($gjenger);
 $array[$diameterF]['ProfilMAX'] = ($dekkprofilF);
 $array[$diameterR]['ProfilMIN'] = ($dekkprofilR);
 $array[$diameterF]['DekkbreddeMIN'] = ($dekkbreddeF);
 $array[$diameterR]['DekkbreddeMAX'] = ($dekkbreddeR);

 }


 print('<pre>');
 print_r('min: '.$minET .' max: '.$maxET .'<br />');
 //print_r($array[$diameterR]['Boltsirkel']);
 print_r($array);
 print('</pre>');  

给我这个:

min: 34 max: 39
Array
  (
  [16] => Array
    (
        [MAX-ET] => 34
        [MIN-ET] => 
        [Felgbredde] => 7,
        [Boltsirkel] => 5x120
        [Navdiameter] => 72.6
        [Gjengetype] => bolt M12 x 1.5
        [ProfilMAX] => 50
        [DekkbreddeMIN] => 225
    )

[] => Array
    (
        [MAX-ET] => 34
        [MIN-ET] => 
        [Felgbredde] => 8,
        [Boltsirkel] => 5x120
        [Navdiameter] => 72.6
        [Gjengetype] => bolt M12 x 1.5
        [ProfilMIN] => 
        [DekkbreddeMAX] => 
    )

[17] => Array
    (
        [MAX-ET] => 37
        [MIN-ET] => 34
        [Felgbredde] => 8,8.5
        [Boltsirkel] => 5x120
        [Navdiameter] => 72.6
        [Gjengetype] => bolt M12 x 1.5
        [ProfilMAX] => 45
        [DekkbreddeMIN] => 225
        [ProfilMIN] => 40
        [DekkbreddeMAX] => 255
    )

[18] => Array
    (
        [MAX-ET] => 37
        [MIN-ET] => 34
        [Felgbredde] => 8,8.5
        [Boltsirkel] => 5x120
        [Navdiameter] => 72.6
        [Gjengetype] => bolt M12 x 1.5
        [ProfilMAX] => 40
        [ProfilMIN] => 35
        [DekkbreddeMIN] => 225
        [DekkbreddeMAX] => 255
    )

[19] => Array
    (
        [MAX-ET] => 39
        [MIN-ET] => 34
        [Felgbredde] => 8,9
        [Boltsirkel] => 5x120
        [Navdiameter] => 72.6
        [Gjengetype] => bolt M12 x 1.5
        [ProfilMAX] => 35
        [ProfilMIN] => 30
        [DekkbreddeMIN] => 225
        [DekkbreddeMAX] => 255
    )

 )