cyberRobot Posted April 12, 2010 Share Posted April 12, 2010 I have a multidimensional array that looks like: $matchingResults[342] = array(id => 342, title => 'Some awesome resource', matches => 3); $matchingResults[5] = array(id => 5, title => 'A great resource', matches => 1); $matchingResults[200] = array(id => 200, title => 'Another ok resource', matches => 1); This array may contain hundreds of items and I want to only display 10 items per page. Is there a simple offset function that I can use to adjust the array pointer. I was thinking about writing a function which would use a loop to manually change the pointer with the next() function. But it seems like there should be a function already available. Link to comment https://forums.phpfreaks.com/topic/198315-modifying-the-pointer-for-a-multidimensional-array/ Share on other sites More sharing options...
JAY6390 Posted April 12, 2010 Share Posted April 12, 2010 If you have to do it like this I would personally use something like array_chunk to split them into blocks of 10, and select the block based on the page number Link to comment https://forums.phpfreaks.com/topic/198315-modifying-the-pointer-for-a-multidimensional-array/#findComment-1040570 Share on other sites More sharing options...
premiso Posted April 12, 2010 Share Posted April 12, 2010 I think the functionality you are looking for is: array_slice. Link to comment https://forums.phpfreaks.com/topic/198315-modifying-the-pointer-for-a-multidimensional-array/#findComment-1040571 Share on other sites More sharing options...
cyberRobot Posted April 13, 2010 Author Share Posted April 13, 2010 array_slice() is exactly what I was looking for. Thanks for everyone's help! Link to comment https://forums.phpfreaks.com/topic/198315-modifying-the-pointer-for-a-multidimensional-array/#findComment-1040918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.