westman Posted December 14, 2011 Share Posted December 14, 2011 i have a 6 number array separated by (,)for example4,29,70,17,49,51,how do i get my random 6 numbers out the array?i tried...$the_number = explode(",", $number);$number1 = array_slice($the_number, 0, 1);$number2 = array_slice($the_number, 0, 2);$number3 = array_slice($the_number, 0, 3);$number4 = array_slice($the_number, 0, 4);$number5 = array_slice($the_number, 0, 5);$number6 = array_slice($the_number, 0, 6);and it did not work Link to comment Share on other sites More sharing options...
dsonesuk Posted December 14, 2011 Share Posted December 14, 2011 <?php $myarray= array(4,29,70,17,49,51);foreach($myarray as $myvalue){echo $myvalue.'<br />';}?> Link to comment Share on other sites More sharing options...
westman Posted December 14, 2011 Author Share Posted December 14, 2011 thank you but how do i get each value of the array in to a variable like... $num1$num2$num3$num4$num5$num6 ? Link to comment Share on other sites More sharing options...
TheGallery Posted December 14, 2011 Share Posted December 14, 2011 $arrayname[0] $arrayname[1]$arrayname[2]$arrayname[3]$arrayname[4]$arrayname[5] you can access the array data like this. Link to comment Share on other sites More sharing options...
dsonesuk Posted December 14, 2011 Share Posted December 14, 2011 <?php$count=1;$myarray= array(4,29,70,17,49,51);foreach($myarray as $myvalue){${'num'.$count} = $myvalue;$count++;}echo $num1.' '.$num2.' '.$num3.' '.$num4.' '.$num5.' '.$num6;?> Link to comment Share on other sites More sharing options...
TheGallery Posted December 14, 2011 Share Posted December 14, 2011 What's wrong with what i suggested dsonesuk? I didn't get his problem right maybe? Link to comment Share on other sites More sharing options...
dsonesuk Posted December 14, 2011 Share Posted December 14, 2011 What's wrong with what i suggested dsonesuk? I didn't get his problem right maybe?There's nothing wrong with you suggestion, I just provided a way of looping through the array values, and use variable variables to assign values to $num1, $num2.. etc what he asked for in his last post. Link to comment Share on other sites More sharing options...
TheGallery Posted December 14, 2011 Share Posted December 14, 2011 I see I am still learning and i thought i didn't get his problem right. Thanks for informing me. Link to comment Share on other sites More sharing options...
westman Posted December 14, 2011 Author Share Posted December 14, 2011 thank you so much they work well thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.