Bijak Antusias Sufi
Bijak Antusias Sufi

Reputation: 197

"SQL LIMIT" in php multidimensional array

How can I do something like

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

in a php multidimensional array?

Upvotes: 0

Views: 541

Answers (3)

fabrik
fabrik

Reputation: 14365

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

Upvotes: 1

Mr Coder
Mr Coder

Reputation: 8186

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

$data is your array

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

Upvotes: 3

Pentium10
Pentium10

Reputation: 207863

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

Upvotes: 0

Related Questions