String matching problem: please kindly advise.

Source: Internet
Author: User
String matching problem: please kindly advise. $ A = "1, 2, 3, 4, 5"
$ B = "1, 2, 3, 4, 6"
$ C = "1, 2, 4, 5, 6"
$ D = "2, 3, 4, 5, 6"
$ F = "7, 8, 9, 10, 11"
How can we determine the similarity between $ B, $ c, $ d, $ f and $? Then, determine their percentage.


Reply to discussion (solution)

Come and help

Prerequisites:
1. sharding
2. the number after splitting must be the same
3. do not perform sequential comparison

Function similarity ($ a, $ B) {$ a_arr = explode (',', $ a); $ B _arr = explode (',', $ B ); $ num = count (array_intersect ($ a_arr, $ B _arr); $ count = count ($ a_arr); return ($ num/$ count * 100 ). '%';} $ a = "1, 2, 3, 4, 5"; $ B = "1, 2, 3, 4, 6"; $ c = "1, 2, 4, 5, 6 "; $ d = "2, 3, 4, 5, 6"; $ f = "7, 8, 9, 10, 11"; echo similarity ($ a, $ B ).'
'; Echo similarity ($ a, $ c ).'
'; Echo similarity ($ a, $ d ).'
'; Echo similarity ($ a, $ f ).'
';

Thanks. I also found this function last night.

Php comes with a similar one. I want to extract user choices from the database and match them with other users. Hey

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.