Skip to content

Instantly share code, notes, and snippets.

@yasaryousuf
Last active August 6, 2019 10:46
Show Gist options
  • Save yasaryousuf/40a67fa6d86800fb3232b3a487c4df6c to your computer and use it in GitHub Desktop.
Save yasaryousuf/40a67fa6d86800fb3232b3a487c4df6c to your computer and use it in GitHub Desktop.
<?php
$hay = 'aabdf';
$nee = 'aaf';
$lenHay = strlen($hay);
$lenNee = strlen($nee);
$arrNee = str_split($nee);
for($i = $lenNee; $i <= $lenHay; $i++){
for($j = 0; $j <= $lenHay - $i;$j++) {
# echo "$i - $j"."\n";
$cropHay = substr($hay,$j,$i);
$arrHay = str_split($cropHay);
echo "--arrNee--";
print_r($arrNee);
echo "--arr inc--";
print_r(array_intersect($arrHay, $arrNee));
if( array_intersect($arrHay, $arrNee) == $arrNee ) { print_r( $arrHay ) ;}
}
echo 'not found';
}
<?php
$hay = 'aabdf';
$nee = 'aaf';
$lenHay = strlen($hay);
$lenNee = strlen($nee);
$arrNee = str_split($nee);
for($i = $lenNee; $i <= $lenHay; $i++){
for($j = 0; $j <= $lenHay - $i;$j++) {
# echo "$i - $j"."\n";
$cropHay = substr($hay,$j,$i);
$arrHay = str_split($cropHay);
if( array_filter(array_values(array_intersect($arrHay, $arrNee))) == $arrNee ) { echo 'paisi' ;}
}
echo 'not found';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment