3 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
我想您想要ID最大的商品:
// get only the items with 'hide' = 1
$hidden = array_filter($array, function($item){return $item['hide'] == 1;});
// order the array to have the items with the greatest ID first
usort($hidden, function($a, $b){
return $b['id'] - $a['id'] ;
});
// print the item with the max id
print_r($hidden[0]);

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
嘗試這個(gè)....。您可以對(duì)關(guān)聯(lián)數(shù)組的任何深度使用此功能。
function is_in_array($array, $key, $key_value){
$within_array = 'no';
foreach( $array as $k=>$v ){
if( is_array($v) ){
$within_array = is_in_array($v, $key, $key_value);
if( $within_array == 'yes' ){
break;
}
} else {
if( $v == $key_value && $k == $key ){
$within_array = 'yes';
break;
}
}
}
return $within_array;
}
print_r(is_in_array($yourarray, 'hide', '1'));

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊
for($i = 0; $i<count($array); $i++){
if($array[$i] == 4){
print_r($array[4]);
}
}
- 3 回答
- 0 關(guān)注
- 205 瀏覽
添加回答
舉報(bào)