如何過濾此數組中的每個數組以僅抓取某些數據片段,如tid
,uid
和device
?從PHP數組中返回多個值
我已經使用array_column
來獲取只有一條信息,但我怎麼能得到多個?
$object = $ticket->find();
$arr = json_decode(json_encode($object), true);
var_dump($arr);
上面的代碼片段是什麼返回數據數組。
array (size=2)
0 =>
array (size=9)
'tid' => string '1' (length=1)
'uid' => string '22' (length=2)
'subject' => string 'iPhone 8' (length=8)
'issue' => string 'iPhone 8 screen replacement' (length=27)
'device' => string 'iPhone 8' (length=8)
'created' => string '2017-05-25 00:01:11' (length=19)
'identifier' => string '29cd54bf' (length=8)
'status' => string 'New' (length=3)
'tech' => string 'None' (length=4)
1 =>
array (size=9)
'tid' => string '2' (length=1)
'uid' => string '22' (length=2)
'subject' => string 'iPhone 7' (length=8)
'issue' => string 'iPhone 7 screen replacement' (length=27)
'device' => string 'iPhone 7' (length=8)
'created' => string '2017-05-25 00:27:42' (length=19)
'identifier' => string 'b47f2c82' (length=8)
'status' => string 'New' (length=3)
'tech' => string 'None' (length=4)
預期輸出:
array(2) {
[0]=> array(3) {
[0]=> string(1) "1"
[1]=> string(2) "22"
[2]=> string(8) "iPhone 8"
}
[1]=> array(3) {
[0]=> string(1) "2"
[1]=> string(2) "22"
[2]=> string(8) "iPhone 7"
}
}
不知道你正在使用但沒有find()方法或find之前的東西允許你限制返回的列嗎? – AbraCadaver