3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $textDump = "apple running gym google"; $keyWordsSports = array("nba", "raptor", "ufc", "basektball", "gym", "mma", "realgm", "running"); $keyWordsTech = array("apple", "rim", "blackberry", "facebook", "twitter", "google" ); $keywords = array("sports"=>$keyWordsSports, "tech"=>$keyWordsTech); $count=array("sports"=>0,"tech"=>0); foreach ($keywords as $key=>$item){ foreach ($item as $newItem){ $count[$key] += substr_count(strtolower($textDump), strtolower($newItem)); } } print_r($count);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [sports] => 2 [tech] => 2 )