【问题标题】:Shuffle Array from Collection从集合中随机播放数组
【发布时间】:2017-09-30 09:22:11
【问题描述】:

我想改组一个数组。但它不会起作用。这是我在 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 这是我收藏的一部分

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 并以洗牌为目标?

【问题讨论】:

标签: php arrays json laravel shuffle


【解决方案1】:

使用这个 $finalShuffleResult = $spielerArray->pluck('Player_ID')->shuffle()->all();

【讨论】:

  • 是array_collection的方法吗?
  • 我测试过了,可以了,是收集方法(收集方法),用就行了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-16
  • 2017-10-07
  • 1970-01-01
  • 1970-01-01
  • 2011-01-27
相关资源
最近更新 更多