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. Link to comment https://forums.phpfreaks.com/topic/162452-solved-array-copy/ 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 ) Link to comment https://forums.phpfreaks.com/topic/162452-solved-array-copy/#findComment-857482 Share on other sites More sharing options...
pkedpker Posted June 16, 2009 Author Share Posted June 16, 2009 Ok sorry :-\ Link to comment https://forums.phpfreaks.com/topic/162452-solved-array-copy/#findComment-857486 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.