pkedpker Posted June 16, 2009 Share Posted June 16, 2009 lol I know this is stupid question but here is what I want to do.. instead of making many arrays I want to access 1 array and get parts of it's elements in all the sub arrays for randomizing them.. so I got $gs = array(1,4,7,10,13,16,19,21,23,27,29,32,37,41,43,46,48,50,52); now I want $ks[] = $gs[6, 12]; so it would copy from 6th index to 12th. and store the 6 elements in ks array. but how do I do that without making a multi-dimensional array as i did. I seen array_slice but it cuts of the original array which is a not and i dont want to make clone of master array just to slice it. Quote Link to comment Share on other sites More sharing options...
.josh Posted June 16, 2009 Share Posted June 16, 2009 array_slice does not overwrite the existing array, unless you assign the results of array_slice to the same array. $gs = array(1,4,7,10,13,16,19,21,23,27,29,32,37,41,43,46,48,50,52); $ks = array_slice($gs,5,6); echo "<pre>"; print_r($gs); print_r($ks); output: Array ( [0] => 1 [1] => 4 [2] => 7 [3] => 10 [4] => 13 [5] => 16 [6] => 19 [7] => 21 [8] => 23 [9] => 27 [10] => 29 [11] => 32 [12] => 37 [13] => 41 [14] => 43 [15] => 46 [16] => 48 [17] => 50 [18] => 52 ) Array ( [0] => 16 [1] => 19 [2] => 21 [3] => 23 [4] => 27 [5] => 29 ) Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 16, 2009 Author Share Posted June 16, 2009 Ok sorry :-\ 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.