1
我有一個PHP數組:PHP濾波器陣列只有一個屬性值
$myarray = array(
array(
'id' = '1',
'number' = '2'
),
array(
'id' = '1',
'number' = '3'
),
array(
'id' = '2',
'number' = '5'
),
array(
'id' = '2',
'number' = '2'
),
);
我需要過濾數組並獲得唯一一個「身份證」與最大數值。
例expecty輸出:
$myarray = array(
array(
'id' = '1',
'number' = '3'
),
array(
'id' = '2',
'number' = '5'
)
);
如何過濾呢?
我試圖循環它,但它沒有工作。
$array = array();
for($i = 0; $i < count($myarray);$i++) {
//If not contains in $array , push to $array
$array []['id'] = $myarray[$x]['id'];
$array []['number'] = $myarray[$x]['number'];
}
告訴我們你嘗試過什麼。 – emaillenin
現在就編輯.. –
你說你「期待只有一個'id'最大數值」,但你的例子輸出顯示了兩個項目。我不清楚。 – karliwson