Solution:
<?php
$arrayOne = explode(' ', readline());
$arrayTwo = explode(' ', readline());
$arrayCommon = [];
$countOne = count($arrayOne);
$countTwo = count($arrayTwo);
for ($i = 0; $i < $countOne; $i++) {
for ($j = 0; $j < $countTwo; $j++) {
if ($arrayOne[$i] == $arrayTwo[$j]) {
$arrayCommon[] = $arrayTwo[$j];
}
}
}
echo implode(' ', $arrayCommon);
I've used explode() and implode() php functions: first to get the strings/integers and create an array with explode() and then to show the elements in the newly created array with implode().