Moore Posted June 4, 2010 Share Posted June 4, 2010 the string holds multiple cases of a category id and a last visited timestamp like so.. (cat_id).(last_visited)/(cat_id).(last_visited) example: ann.1275669173/sugg.1275669055/upd.1275668000 what i want to do is create an array where the key is the category id (before '.') and the value is the timestamp (after '.'), like so: $New[ann] would equal 1275669173 $New[sugg] would equal 1275669055 $New[upd] would equal 1275668000 and so on.. i hope someone can help out here.. i'm pretty stuck Quote Link to comment https://forums.phpfreaks.com/topic/203874-trying-to-explode-a-string/ Share on other sites More sharing options...
TheBG Posted June 4, 2010 Share Posted June 4, 2010 explode on the '/' which will give you an array of array['name' and array['time'] then just loop through that array. Quote Link to comment https://forums.phpfreaks.com/topic/203874-trying-to-explode-a-string/#findComment-1067769 Share on other sites More sharing options...
Alex Posted June 4, 2010 Share Posted June 4, 2010 $str = 'ann.1275669173/sugg.1275669055/upd.1275668000'; $new = array(); foreach(explode('/', $str); as $part){ $s = explode('.', $part); $new[$s[0]] = $s[1]; } Quote Link to comment https://forums.phpfreaks.com/topic/203874-trying-to-explode-a-string/#findComment-1067774 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.