Jump to content

[SOLVED] Anybody want to learn the array_count_values() php function HERE U GO.....


redarrow

Recommended Posts

 

 

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.