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? Link to comment https://forums.phpfreaks.com/topic/132749-solved-separate/ 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... Link to comment https://forums.phpfreaks.com/topic/132749-solved-separate/#findComment-690351 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 Link to comment https://forums.phpfreaks.com/topic/132749-solved-separate/#findComment-690353 Share on other sites More sharing options...
greenba Posted November 14, 2008 Author Share Posted November 14, 2008 Thanx Link to comment https://forums.phpfreaks.com/topic/132749-solved-separate/#findComment-690393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.