Jayfromsandiego Posted February 21, 2019 Share Posted February 21, 2019 (edited) Hello group. I need some help with my code. <?php $a1 = array("line1"=>"1-2-3-10-14","line2"=>"1-2-3-10-34","line3"=>"1-2-7-16-35","line4"=>"1-2-3-17-19","line5"=>"2-5-11-15-32"); $a2 = array("inputnumber"=>"1-2-3-10-34"); $result = array_intersect($a1,$a2); print_r($result); ?> Right now, I can only search and find an exact match of all 5-Numbers. I want to code a PHP form that will take a (5-number string) as input and then compare that string against an array database of (5-number strings) to find all matching number occurrences for each “LINE 1 thru LINE 5”. For instance, if I were to type the 5-number string “1-2-3-10-34” as input. The Output populated results would look like this .. Edited February 21, 2019 by Jayfromsandiego Quote Link to comment https://forums.phpfreaks.com/topic/308365-matching-number-elements/ Share on other sites More sharing options...
requinix Posted February 21, 2019 Share Posted February 21, 2019 Working with those numbers as a string is proving to be a pain, isn't it? Then don't work with them as a string. Use an array, for both the input as well as the stored numbers. You can display them as a hyphenated string, but internally keep them as an array. explode() and implode() can help you convert between the two forms. Then the problem is how to take an array of five numbers and check against other arrays of five numbers to find what they have in common. Fortunately there's a function for that. Quote Link to comment https://forums.phpfreaks.com/topic/308365-matching-number-elements/#findComment-1564674 Share on other sites More sharing options...
Jayfromsandiego Posted February 21, 2019 Author Share Posted February 21, 2019 Thank you for your help and suggestions, as always requinix. ? I think I am also going to look into >> array_diff($a, $b), Quote Link to comment https://forums.phpfreaks.com/topic/308365-matching-number-elements/#findComment-1564675 Share on other sites More sharing options...
Barand Posted February 21, 2019 Share Posted February 21, 2019 You may find my reply to one of your previous topics of interest here. (I sometimes ask myself why we bother) 2 Quote Link to comment https://forums.phpfreaks.com/topic/308365-matching-number-elements/#findComment-1564676 Share on other sites More sharing options...
Jayfromsandiego Posted February 24, 2019 Author Share Posted February 24, 2019 (edited) Barand that's exactly what I needed. Thank you for pointing that reference point again. Edited February 24, 2019 by Jayfromsandiego Quote Link to comment https://forums.phpfreaks.com/topic/308365-matching-number-elements/#findComment-1564765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.