开发者

"SQL LIMIT" in php multidimensional array

开发者 https://www.devze.com 2023-02-16 23:49 出处:网络
How can I do 开发者_JS百科something like SELECT * from table LIMIT \'10\',\'50\' in a php multidimensional array?use array_slice http://php.net/manual/en/function.array-slice.php

How can I do 开发者_JS百科something like

SELECT * from table LIMIT '10','50'

in a php multidimensional array?


use array_slice http://php.net/manual/en/function.array-slice.php

$data is your array

$myData = array_slice($data,10,50);


Maybe you're looking for array_slice.

<?php
$input = array("a", "b", "c", "d", "e");

$output = array_slice($input, 2);      // returns "c", "d", and "e"
$output = array_slice($input, -2, 1);  // returns "d"
$output = array_slice($input, 0, 3);   // returns "a", "b", and "c"

// note the differences in the array keys
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));
?>

Because you didn't provided many details about your arrays, i can't provide better example than this one above.

//pseudo code
foreach($your_whole_array as $child_array) {
    $limited_array[] = array_slice($child_array, 0, 2);
}

//$limited_array now contains your limited data


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号