Hi
Im trying to find a quick and easy way of counting the number of instances of a string inside an array.
in_array() tells me whether a string exists in an array, which is great, but when i try to use it like this;
$filename="../logs/error_log";
//read in the entire file. Each order becomes an element in the array
$orders= file($filename);
$count=in_array("tellafriend", $orders) ;
$count=substr_count ($count, "tellafriend");
it returns 0 and yet I know that there are at least 3 instances within the log.
$count("tellafriend tellafriend blah dfh tellafriend") ;
$count=substr_count ($count, "tellafriend");
returns 3 as expected, so the reason it doesn't work points me to the fact that substr_count will not work with arrays.
So, does anyone know an easy way of counting the number of times a string appears in an array?
I'd appreciate it, as Im beginning to go around in circles (its been fun though 😉)
Thanks for any ideas.
Rob