shamuraq Posted July 28, 2009 Share Posted July 28, 2009 Hi all for($x1 = 0; $x1 < $lebar; $x1++){ $x1 = $x1 + 30; $a = array( '#FFFFFF', '#666666'); $a1 = $a[array_rand($a)]; } How do i count the number of "#FFFFFF" and "#666666" being output? Thanx in advance... Quote Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/ Share on other sites More sharing options...
gevans Posted July 28, 2009 Share Posted July 28, 2009 You're not outputting any right there Quote Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/#findComment-884726 Share on other sites More sharing options...
patrickmvi Posted July 28, 2009 Share Posted July 28, 2009 I believe this will do what you're looking for: $output_counts = array(); for($x1 = 0; $x1 < $lebar; $x1++){ $x1 = $x1 + 30; $a = array( '#FFFFFF', '#666666'); $a1 = $a[array_rand($a)]; $output_counts[$a1]++; } print_r($output_counts); Quote Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/#findComment-884825 Share on other sites More sharing options...
tommyda Posted July 28, 2009 Share Posted July 28, 2009 Try looking into sizeof(); sizeof($a); or sizeof($al); Quote Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/#findComment-884829 Share on other sites More sharing options...
shamuraq Posted July 29, 2009 Author Share Posted July 29, 2009 I believe this will do what you're looking for: $output_counts = array(); for($x1 = 0; $x1 < $lebar; $x1++){ $x1 = $x1 + 30; $a = array( '#FFFFFF', '#666666'); $a1 = $a[array_rand($a)]; $output_counts[$a1]++; } print_r($output_counts); That's exactly what i am looking for but how do i store these results into different variable? eg; i want to store $color1 = count '#FFFFFF'; $color2 = count '#666666'; Thanx again patrick Quote Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/#findComment-886046 Share on other sites More sharing options...
.josh Posted July 29, 2009 Share Posted July 29, 2009 $color1 = $output_counts['#FFFFFF']; $color2 = $output_counts['#666666']; Quote Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/#findComment-886063 Share on other sites More sharing options...
shamuraq Posted July 29, 2009 Author Share Posted July 29, 2009 Wooooohooooooo... Thanx Patrick... Thanx Crayon Violent !!! Outstanding help guys... At least for a dumb wit like me... Quote Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/#findComment-886071 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.