asmith Posted January 10, 2009 Share Posted January 10, 2009 Hi, I wanna explode an string into an array, but I want the array to start from 1, not 0. Is there a function or a simple line for that ? or I have to code it? Quote Link to comment https://forums.phpfreaks.com/topic/140311-solved-explode-string-but-array-start-at-1/ Share on other sites More sharing options...
auro Posted January 10, 2009 Share Posted January 10, 2009 You can simply use the -1 to call array items friend. Quote Link to comment https://forums.phpfreaks.com/topic/140311-solved-explode-string-but-array-start-at-1/#findComment-734207 Share on other sites More sharing options...
asmith Posted January 10, 2009 Author Share Posted January 10, 2009 Isn't it for php5 mate? I don't have php5 Unless you're talking about something else? Quote Link to comment https://forums.phpfreaks.com/topic/140311-solved-explode-string-but-array-start-at-1/#findComment-734210 Share on other sites More sharing options...
GingerRobot Posted January 10, 2009 Share Posted January 10, 2009 No, he's suggesting that you just take one from whatever number your using that relies on the index starting at one. A good suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/140311-solved-explode-string-but-array-start-at-1/#findComment-734211 Share on other sites More sharing options...
.josh Posted January 10, 2009 Share Posted January 10, 2009 If you insist, you could always do something like this: $array = array('a','b','c','d','e'); $c = count($array); for ($x = 1; $x <= $c; $x++) { $tarray[$x] = $array[$x-1]; } $array = $tarray; Though I'd personally just do the ..-1 thing already mentioned. Quote Link to comment https://forums.phpfreaks.com/topic/140311-solved-explode-string-but-array-start-at-1/#findComment-734218 Share on other sites More sharing options...
asmith Posted January 10, 2009 Author Share Posted January 10, 2009 oh yea lol I got it now. Unfortunately the array indexes, each number has a special meaning in the script. so I wanna make less confusion. CV, Thanks for the code, That's actually my last chance. I wanted to make sure there's isn't any built-in thing on php Quote Link to comment https://forums.phpfreaks.com/topic/140311-solved-explode-string-but-array-start-at-1/#findComment-734228 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.