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... 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 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); 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); 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 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']; 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... Link to comment https://forums.phpfreaks.com/topic/167770-solved-count-within-array/#findComment-886071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.