3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrayA=[ 'Red', 'Black', 'White', 'Green' ]; $arrayB=[ 'Blackwell', 'Purple', 'Whitewater', 'Reddit' ]; // similar text foreach($arrayA as $a){ $temp=array_combine($arrayB,array_map(function($v)use($a){similar_text($v,$a,$percent); return $percent;},$arrayB)); // generate assoc array of assessments arsort($temp); // sort descending $result[]="$a is most similar to ".key($temp)." (sim-score:".number_format(current($temp))."%)"; // access first key and value } var_export($result); echo "\n--\n"; // levenstein doesn't offer the desired matching foreach($arrayA as $a){ $temp=array_combine($arrayB,array_map(function($v)use($a){return levenshtein($v,$a);},$arrayB)); // generate assoc array of assessments arsort($temp); // sort descending $result2[]="$a is most similar to ".key($temp)." (lev-score:".current($temp).")"; // access first key and value } var_export($result2);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
array ( 0 => 'Red is most similar to Reddit (sim-score:67%)', 1 => 'Black is most similar to Blackwell (sim-score:71%)', 2 => 'White is most similar to Whitewater (sim-score:67%)', 3 => 'Green is most similar to Purple (sim-score:36%)', ) -- array ( 0 => 'Red is most similar to Whitewater (lev-score:9)', 1 => 'Black is most similar to Whitewater (lev-score:9)', 2 => 'White is most similar to Blackwell (lev-score:8)', 3 => 'Green is most similar to Blackwell (lev-score:8)', )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
200.43 ms | 408 KiB | 5 Q