简体   繁体   English

如何限制PHP数组中返回的结果

[英]how to limit results that are returned in a PHP array

I have this foreach loop in PHP where i loop through some array results: 我在PHP中有这个foreach循环,在其中循环遍历了一些数组结果:

foreach(array_reverse($output) as $row)

but i want to be able to limit the number of results so i can display the results on separate pages 但我希望能够限制结果的数量,以便可以在单独的页面上显示结果

i have tried using the function array_slice in PHP but had no luck, using the below code i just get no results returned 我已经尝试在PHP中使用函数array_slice但没有运气,使用下面的代码我只是没有得到任何结果

foreach(array_reverse(array_slice($output),0,5) as $row)

how can i limit the results returned in the array? 如何限制数组中返回的结果?

您将偏移量和限制值放在array_reverse方法参数而不是array_slice参数中。

array array_reverse ( array $array [, bool $preserve_keys = false ] )

array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = false ]] )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM