- array_count_values: documentation ( source)
- explode: documentation ( source)
- strtolower: documentation ( source)
<?php
$input ="we are the people who are selected by the people of country who gave vote.";
$words = array_count_values(explode(' ', strtolower($input)));
$first_occ = '';
foreach ($words as $word => $count) {
if ($count > 1) {
$first_occ = $word;
break;
}
}
echo $first_occ;