PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php //Найти общие части слов function GetCommonParts(array $source) { $parts = []; foreach($source as $k => $v) { $symbols = mb_str_split(mb_strtolower($v)); for($i = mb_strlen($v); $i > 0; $i--) { $kk = ''; foreach(array_slice($symbols, -$i) as $symbol) { $kk .= $symbol; $parts[$k][$kk] = null; } } } return $parts ? array_keys(array_intersect_key(...$parts)) : []; } $words = [ 'привет', 'живет', ]; print_r(GetCommonParts($words)); ?>
Show:  
Copy Clear