Page 1 of 1

Search and desplay....array?

Posted: Wed Nov 05, 2003 4:12 pm
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/ :?

Posted: Wed Nov 05, 2003 5:20 pm
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));
?>

Posted: Wed Nov 05, 2003 5:34 pm
by m3mn0n
Reference material: [php_man]arrays[/php_man]