0

How can I do something like

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

in a php multidimensional array?

1
  • 1
    Could you provide some input ? Commented Mar 16, 2011 at 12:52

3 Answers 3

3

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

$data is your array

$myData = array_slice($data,10,50);
Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

hey, it is the details array : $array['post'] = array( array( Title => "rose", Price => 1.25, Number => 15 ), array( Title => "daisy", Price => 0.75, Number => 25, ), array( Title => "orchid", Price => 1.15, Number => 7 ) );
Yeah, this is an array. But i don't know anything about your rules to apply on it. You can iterate through $array['post'] with foreach then slice every child array based on your rules.
0
array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys = false ]] )

2 Comments

hey, it is the details array : $shop['entry'] = array( array( Title => "rose", Price => 1.25, Number => 15 ), array( Title => "daisy", Price => 0.75, Number => 25, ), array( Title => "orchid", Price => 1.15, Number => 7 ) );
How did you tried? what print_r(array_slice($shop['entry'],10,50)); produces?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.