3v4l.org

run code in 500+ PHP versions simultaneously
<?php $usr = (object)[ 'interests' => 'Cats,Dogs,Monkeys,Praying Mantises,Octopuses,Arowanas,Sloths,Tasmanian Tigers' ]; $showMax = 3; printf( 'Interested in: %s', preg_replace_callback_array( [ '/([^,]+)(,)?/' => fn($m) => '<span>' . $m[1] . '</span>' . (isset($m[2]) ? ', ' : ''), '/, [^<].*/' => fn($m) => ' (+' . substr_count($m[0], ',') . ')' ], $usr->interests, $showMax ) );

preferences:
40.55 ms | 847 KiB | 5 Q