Search and desplay....array?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wesnoel
Forum Commoner
Posts: 58
Joined: Fri Sep 05, 2003 11:53 am

Search and desplay....array?

Post by wesnoel »

OK I know how to add to an array but how can I search an array and count the number of occurrences of matching words in that array and then print each with the count next to it?

What I'm doing is looping through a directory of CSV files reading each file and pulling out the 3rd delimiter which are the initials of a user that submitted a form. What I want to do is figure out how many times each user has submitted the form in a given month.

Can this be done like this? or am I on the wrong track.

TIA,

Wes/ :?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

This might give you somepointers. You need to add bits and pieces for it to work for you tho.

Code: Select all

<pre>
<?php
$array[] = 'foo|JAM|bar';
$array[] = 'foo|Sami|bar';
$array[] = 'foo|jason|bar';
$array[] = 'foo|Mac|bar';
$array[] = 'foo|Mac|bar';
$array[] = 'foo|Mac|bar';
$array[] = 'foo|jason|bar';
$array[] = 'foo|Sami|bar';

foreach ($array as $key => $value) {
    $x = explode('|',$value);
    $arr[$key] = $x[1];
}
    // the new array
    print_r($arr);
    // counting values
    print_r(array_count_values($arr));
?>
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Reference material: [php_man]arrays[/php_man]
Post Reply