3v4l.org

run code in 300+ PHP versions simultaneously
<?php $interesting_words = [ 'test' => [ 'number_of_occurances' => 0, 'connected_words' => [ 'TEST', 'TESTER', 'TESTING' ] ], 'foobar' => [ 'number_of_occurances' => 0, 'connected_words' => [ 'FOO', 'FOOBAR', 'BAR' ] ] ]; $str = 'Lorem ipsum TEST sit amet, consectetur TESTER elit. Sed in turpis dui. Maecenas venenatis FOOBAR facilisis. Quisque dictum, diam consequat mollis TESTING, orci tellus aliquet nisl, BAR molestie FOO augue at est. In TESTING vehicula lectus. Curabitur ac varius ligula. Pellentesque orci urdna.'; $str = preg_replace('/[\.\,]/i','',$str); $str = strtolower($str); $str_arr = explode(" ",$str); $str_occurance_counts = array_count_values($str_arr); foreach($interesting_words as $k=>&$v){ foreach($v['connected_words'] as $c=>$cVal){ $v['number_of_occurances'] += $str_occurance_counts[strtolower($cVal)]; } echo "Number of occurances for '$k': ".$v['number_of_occurances']."\n"; } print_r($interesting_words ); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Number of occurances for 'test': 4 Number of occurances for 'foobar': 3 Array ( [test] => Array ( [number_of_occurances] => 4 [connected_words] => Array ( [0] => TEST [1] => TESTER [2] => TESTING ) ) [foobar] => Array ( [number_of_occurances] => 3 [connected_words] => Array ( [0] => FOO [1] => FOOBAR [2] => BAR ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
55.55 ms | 402 KiB | 8 Q