alin19 Posted May 9, 2008 Share Posted May 9, 2008 i have an array that contains like this: how can i count how many times each string apears? ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV01 ESTINV03 ESTINV03 ESTINV03 ESTINV03 ESTINV03 ESTINV04 ESTINV04 ESTINV04 ESTINV05 ESTINV05 ESTINV05 ESTINV05 ESTINV05 ESTINV06 ESTINV06 ESTINV08 ESTINV08 ESTINV08 ESTINV08 ESTINV08 ESTINV08 ESTINV09 ESTINV12 ESTINV12 ESTINV12 ESTINV12 ESTINV12 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV16 ESTINV17 ESTINV17 ESTINV17 ESTINV17 ESTINV17 ESTINV17 ESTINV17 ESTINV17 ESTINV18 ESTINV18 ESTINV18 ESTINV18 ESTINV18 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV21 ESTINV22 ESTINV25 ESTINV25 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV26 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV27 ESTINV28 ESTINV28 ESTINV28 ESTINV31 ESTINV32 ESTINV32 ESTINV34 ESTINV36 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV37 ESTINV38 ESTINV39 ESTINV39 ESTINV39 ESTINV39 ESTINV39 Link to comment https://forums.phpfreaks.com/topic/104845-counting-strings-in-array/ Share on other sites More sharing options...
whatever Posted May 9, 2008 Share Posted May 9, 2008 use array_unique($array_name) Link to comment https://forums.phpfreaks.com/topic/104845-counting-strings-in-array/#findComment-536644 Share on other sites More sharing options...
alin19 Posted May 9, 2008 Author Share Posted May 9, 2008 can you explin it how do i use it? Link to comment https://forums.phpfreaks.com/topic/104845-counting-strings-in-array/#findComment-536646 Share on other sites More sharing options...
whatever Posted May 9, 2008 Share Posted May 9, 2008 http://ie2.php.net/array_unique Link to comment https://forums.phpfreaks.com/topic/104845-counting-strings-in-array/#findComment-536648 Share on other sites More sharing options...
alin19 Posted May 9, 2008 Author Share Posted May 9, 2008 and how do i count each time an array apears? Link to comment https://forums.phpfreaks.com/topic/104845-counting-strings-in-array/#findComment-536654 Share on other sites More sharing options...
PFMaBiSmAd Posted May 9, 2008 Share Posted May 9, 2008 Use array_count_values() instead. Link to comment https://forums.phpfreaks.com/topic/104845-counting-strings-in-array/#findComment-536657 Share on other sites More sharing options...
alin19 Posted May 9, 2008 Author Share Posted May 9, 2008 10x, I use them both and it works : for ($i=0;$i<$x;$i++) { $lines=explode(" ",$fp[$i]); $agenti=explode("-",$lines[3]); $ag[]=$agenti[0]; } $y=array_count_values($ag); $x=array_unique($ag); foreach ($x as $test) { echo $test.$y[$test]."\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/104845-counting-strings-in-array/#findComment-536659 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.