Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Laravel 5.4跳过Pull数组中的第一个值_Arrays_Laravel_Laravel 5.4_Pluck - Fatal编程技术网

Arrays Laravel 5.4跳过Pull数组中的第一个值

Arrays Laravel 5.4跳过Pull数组中的第一个值,arrays,laravel,laravel-5.4,pluck,Arrays,Laravel,Laravel 5.4,Pluck,我有这个疑问 $orderStates = OrderState::listsTranslations( 'states' )->pluck( 'states', 'id' )->toArray(); 这将输出类似于 array:3 [▼ 1 => "waiting" 2 => "agreed" 3 => "canceled" ] array:3 [▼ 2 => "agreed" 3 => "canceled"

我有这个疑问

$orderStates = OrderState::listsTranslations( 'states' )->pluck( 'states', 'id' )->toArray();
这将输出类似于

array:3 [▼
  1 => "waiting"
  2 => "agreed"
  3 => "canceled"
]
array:3 [▼
      2 => "agreed"
      3 => "canceled"
    ]
我需要跳过第一个这样的

array:3 [▼
  1 => "waiting"
  2 => "agreed"
  3 => "canceled"
]
array:3 [▼
      2 => "agreed"
      3 => "canceled"
    ]

请问如何做到这一点?

有多种方法可以做到这一点。在我看来不太一致的一个方法是使用
skip(1)
(这要求查询按
id
排序,并且总是需要跳过id=1的条目):

另一种方法是使用
whereNotIn()
排除特定的
id

$orderStates = OrderState::listsTranslations( 'states' )
    ->whereNotIn('id', [1])
    ->pluck( 'states', 'id' )
    ->toArray();

您也可以使用
where('id',!=',1)
而不是
whereNotIn('id',[1])
skip(1)
,但我个人认为
whereNotIn
为未来提供了最大的扩展性。

首先感谢Namoshek指南,但是
skip(1)
没有使用它,但是
slice(1)
使用了它

这是最后一个查询

$orderStates = OrderState::listsTranslations( 'states' )
                                 ->pluck( 'states', 'id' )
                                 ->slice( 1 )
                                 ->toArray();

工作正常。

感谢您的回复,但没有与我一起工作尝试跳过(1)获得
SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以了解第1行“偏移量1”附近使用的正确语法(SQL:选择
order\u states
order\u state\u translations
states`from
order\u states
left join
order\u state\u translations
上的
order\u state\u translations
=
order\u states
id
其中
order\u state\u translations
locale=ar offset 1)`Hm是的,这实际上是您在那里运行的MySQL的一个限制。如果您要添加一个
限制(100)
(或任何其他大于您希望从数据库接收的记录数量的数字),它会工作的。但由于这是一个黑客程序,并且添加了一些将来可能无法调试的功能,所以最好远离它。