bruceblacklaws Posted August 19, 2013 Share Posted August 19, 2013 I'm looking for a way to remove all but the last 10 elements in an array. Is it possible to do this with array_splice? I have an array with greater than 1000 elements and I don't want to have to specify each element I want to remove. It would be cool if I could do something like "remove elements 1-990". Quote Link to comment Share on other sites More sharing options...
PravinS Posted August 19, 2013 Share Posted August 19, 2013 (edited) user array_slice() like array_slice($array,0,-10) Edited August 19, 2013 by PravinS Quote Link to comment Share on other sites More sharing options...
bruceblacklaws Posted August 19, 2013 Author Share Posted August 19, 2013 (edited) user array_slice() like array_slice($array,0,-10) Thanks. That worked. $a = [ "1" => "test1", "2" => "test2", "3" => "test3", "4" => "test4", "5" => "test5", "6" => "test6", "7" => "test7", "8" => "test8", "9" => "test9", "10" => "test10", "11" => "test11", "12" => "test12", "13" => "test13", "14" => "test14", "15" => "test15", "16" => "test16", "17" => "test17", "18" => "test18", "19" => "test19", "20" => "test20" ]; array_splice($a, 1, -10); print_r($a); Edited August 19, 2013 by bruceblacklaws Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.