3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Return the coefficient of two items based on Jaccard index * http://en.wikipedia.org/wiki/Jaccard_index * * Example: * * $tags1 = "code, php, jaccard, test, items"; * $tags2 = "test, code"; * echo getSimilarityCoefficient( $tags1, $tags2 ); // 0.28 * * $str1 = "similarity coefficient of two items"; * $str2 = "two items are cool"; * echo getSimilarityCoefficient( $str1, $str2, " " ); // 0.44 * * @param string $item1 * @param string $item2 * @param string $separator * @return float * @author Henrique Hohmann * @version 0.1 */ function getSimilarityCoefficient( $item1, $item2, $separator = "," ) { $item1 = explode( $separator, $item1 ); $item2 = explode( $separator, $item2 ); $arr_intersection = array_intersect( $item2, $item2 ); $arr_union = array_merge( $item1, $item2 ); $coefficient = count( $arr_intersection ) / count( $arr_union ); return $coefficient; } print(getSimilarityCoefficient('SA PRESTASHOP', strtoupper('PrestaShop SA')));
Output for git.master, git.master_jit, rfc.property-hooks
0.5

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
59.78 ms | 401 KiB | 8 Q