从 Collection 随机排列数组
Shuffle Array from Collection
我想洗牌一个数组。但这是行不通的。这是我在 Laravel
中的查询
$spielerArray = Spieler::join('PlanungSpieler', 'PlanungSpieler.Player_ID', '=', 'Spieler.Player_ID')
->select('Spieler.Player_ID')->get();
在下一步中,我只想随机播放列 Spieler.Player。
$finalShuffleResult = shuffle($spielerArray->Player_ID)
我明白了 Player_ID Instance does not exist on this collection
这是我的一部分 collection
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Spieler Object
(
[table:protected] => Spieler
[connection:protected] => mysql
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[withCount:protected] => Array
(
)
[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[Player_ID] => 101
)
我怎样才能得到 Player_ID 来洗牌?
使用这个
$finalShuffleResult = $spielerArray->pluck('Player_ID')->shuffle()->all();
我想洗牌一个数组。但这是行不通的。这是我在 Laravel
中的查询$spielerArray = Spieler::join('PlanungSpieler', 'PlanungSpieler.Player_ID', '=', 'Spieler.Player_ID')
->select('Spieler.Player_ID')->get();
在下一步中,我只想随机播放列 Spieler.Player。
$finalShuffleResult = shuffle($spielerArray->Player_ID)
我明白了 Player_ID Instance does not exist on this collection
这是我的一部分 collection
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Spieler Object
(
[table:protected] => Spieler
[connection:protected] => mysql
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[withCount:protected] => Array
(
)
[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[Player_ID] => 101
)
我怎样才能得到 Player_ID 来洗牌?
使用这个
$finalShuffleResult = $spielerArray->pluck('Player_ID')->shuffle()->all();