greenba Posted November 14, 2008 Share Posted November 14, 2008 Hi, I have a string "1234567" and I would like to separate it so that each number has its own variable so that: $var1 = "1"; $var2 = "2"; and so on... Any ideas? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 14, 2008 Share Posted November 14, 2008 um...like this? <?php $string = '1234567'; foreach(explode('',$string) as $num){ ${'var'.$num} = $num; } ?> But that is silly in my opinion. Just use an array... Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 14, 2008 Share Posted November 14, 2008 And technically each number already does have it's own variable. <?php $string = '123'; echo $string[0]; echo $string[1]; echo $string[2]; ?> 123 Quote Link to comment Share on other sites More sharing options...
greenba Posted November 14, 2008 Author Share Posted November 14, 2008 Thanx 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.