偏移我$arrLevel
從截枝結果:繼續遍歷PHP
Array
(
[0] => Array
(
[ohp_id] => 98
[parent_ohp_id] => 84
[organization_id] => 122
[position_id] => 32
[level] => 3
[seat] => 1
[description] =>
[start_date] => 2016-07-21
[end_date] =>
[title] => Coordinator Of Support Operational and Mainte
)
)
Array
(
[0] => Array
(
[ohp_id] => 84
[parent_ohp_id] =>
[organization_id] => 122
[position_id] => 2
[level] => 2
[seat] => 1
[description] =>
[start_date] => 2016-07-21
[end_date] =>
[title] => Chief
)
)
etc...
他們中的一個具有空parent_ohp_id
,並在我的代碼提示錯誤Notice: Undefined offset: 1
。這是我的代碼:
for ($i = 0; $i < count($arrPosition); $i++) {
$hasPosition->loadHas($orgId, $arrPosition[$i]);
$level = search($arr, 'level', $arrLevel[$i]);
//print_r($level);
if(isset($level[$i]['parent_ohp_id'])){
if((int)$level[$i]['parent_ohp_id'] == (int)$level[$i]['ohp_id']){
$parentOhp = null;
}
else{
$parentOhp = $level[$i]['parent_ohp_id'];
}
}
else{
$parentOhp = null;
}
etc...
原因偏移,循環過程停止和所有數組後,它無法顯示/無法繼續循環。如何解決它並將未定義的偏移量parent_ohp_id
設置爲null
?謝謝...
它解決了錯誤更換你的代碼,但仍不能繼續循環 –