redarrow Posted October 13, 2008 Share Posted October 13, 2008 I had to learn this array function if a ip was twice in the database, i can tell the user that there download was not allowed and they have download twice..... Anybody want to learn the array_count_values() php function HERE U GO..... <?php //array way to find x amount off people using array_count values() php function... $x=array("john","lucky","john","petter","luke","petter","brian","petter"); $count=array_count_values($x); $name=array("john","petter"); if($count[$name[0]] ==2 && $count[$name[1]]==3){ echo "{$name[0]} is there {$count[$name[0]]}times! and {$name[1]} is there {$count[$name[1]]} times! <br><br>"; print_r($count); } echo"<br><br>"; //varable way to find x amount off people using array_count values() php function... $x=array("john","lucky","john","petter","luke","petter","brian","petter"); $count=array_count_values($x); $name1="john"; $name2="petter"; if($count[$name1] ==2 && $count[$name2]==3){ echo "{$name1} is there {$count[$name1]}times! and {$name2} is there {$count[$name2]} times! <br><br>"; print_r($count); } ?> Link to comment https://forums.phpfreaks.com/topic/128240-solved-anybody-want-to-learn-the-array_count_values-php-function-here-u-go/ Share on other sites More sharing options...
redarrow Posted October 13, 2008 Author Share Posted October 13, 2008 according to everythink i have read php 6 will allow the [] and the {} to be used to echo statement out is it correct... php above version 6 [] not allowed <?php echo "{$name1} is there {$count[$name1]}times! and {$name2} is there {$count[$name2]} times! <br><br>"; ?> php version 6 both ways allowed <?php echo "{$name1} is there {$count[$name1]}times! and {$name2} is there {$count[$name2]} times! <br><br>"; echo "[$name1] is there [$count[$name1]]times! and [$name2] is there [$count[$name2]] times! <br><br>"; ?> Link to comment https://forums.phpfreaks.com/topic/128240-solved-anybody-want-to-learn-the-array_count_values-php-function-here-u-go/#findComment-664152 Share on other sites More sharing options...
redarrow Posted October 13, 2008 Author Share Posted October 13, 2008 This is why i had to learn the function off array_count_values For some terrable reason in_array has not got the abilty to let you increment the desired search, so if you wanted john twice there no way with in_array as a solo function............... about time it was added theo....... <?php $x=array("john","lucky","john","petter","luke","petter","brian","petter"); $name="john"; for($i=2; $i<3; $i++){ if(in_array(".$name[$i].",$x)){ echo" $name[$i] is there"; } } ?> Link to comment https://forums.phpfreaks.com/topic/128240-solved-anybody-want-to-learn-the-array_count_values-php-function-here-u-go/#findComment-664165 Share on other sites More sharing options...
wildteen88 Posted October 13, 2008 Share Posted October 13, 2008 Sorry but what the hell are you going on about? in_array is used to see if a value is contained within an array. It wont return how many times that value is in the array. That is why the array_count_value exists. Link to comment https://forums.phpfreaks.com/topic/128240-solved-anybody-want-to-learn-the-array_count_values-php-function-here-u-go/#findComment-664175 Share on other sites More sharing options...
redarrow Posted October 13, 2008 Author Share Posted October 13, 2008 I agree but would be nice if you was able to have a third pramater to see sometink x times... example <?php if(in_array("john",$array,2)}{ // what ever } ?> surley make life easer........ Link to comment https://forums.phpfreaks.com/topic/128240-solved-anybody-want-to-learn-the-array_count_values-php-function-here-u-go/#findComment-664182 Share on other sites More sharing options...
wildteen88 Posted October 13, 2008 Share Posted October 13, 2008 No as that would not make any sense. Link to comment https://forums.phpfreaks.com/topic/128240-solved-anybody-want-to-learn-the-array_count_values-php-function-here-u-go/#findComment-664189 Share on other sites More sharing options...
redarrow Posted October 13, 2008 Author Share Posted October 13, 2008 ok wildteen was only a thort im going mad....... Link to comment https://forums.phpfreaks.com/topic/128240-solved-anybody-want-to-learn-the-array_count_values-php-function-here-u-go/#findComment-664192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.