0

This question relates to Francois Deschenes's answer to one of my previous questions.

I am unsure how to apply my text similarity check function to the array_uintersect function.

Here is my function (Open for ideas on improvement):

function checkSimilar($str1, $str2){
    similar_text($str1, $str2, $percent);
    if($percent > 75){ 
        return $str2; 
    }
    else{ 
        return null;
    }
}
Community
  • 1
  • 1
Michael Ecklund
  • 1,206
  • 2
  • 17
  • 30
  • Do you want to sort the array by matching percentage? This has nothing to do with `array_unintersect`. – Halcyon Jun 18 '11 at 23:00
  • @Frits van Campen This question is based off another question which I linked at the top of this question. Please read the other link. We used array_uintersect... I was told to create a function that uses similar_text() and to replace the function in the array_uintersect line, however -- It does not appear to be working. :-\ – Michael Ecklund Jun 20 '11 at 16:00
  • But to explain my self again, I have two arrays. The user inputted song titles, and the song titles (how they appear on the source) looked up on external sources. I want to sort the song titles that have been looked up on the external sources by the order of the user inputted song titles. just sorting one array by the other array's order. – Michael Ecklund Jun 20 '11 at 16:03

1 Answers1

1

Well this might be silly what I am saying, I don't know, but I don't understand why you have an array with such keys (values, as shown in your other post). Not really sure what you are trying to do, I just made a guess that you need only one array with maybe 2 dimensions (just a guess, not sure):

<?php

 $song[]=array('title'=>'boing', 'singer'=>'john smith', 'year'=>'1949');
 $song[]=array('title'=>'Don\'t Trust me', 'singer'=>'3oh!3', 'year'=>'1929');
 $song[]=array('title'=>'You Belong with me', 'singer'=>'Taylor Swift', 'year'=>'1981');
 $song[]=array('title'=>'You Belong to earth', 'singer'=>'Taylor Swift', 'year'=>'1991');
 $song[]=array('title'=>'You Do  Belong Everywhere', 'singer'=>'Taylor Swift', 'year'=>'1971');
 $song[]=array('title'=>'Fire Burning', 'singer'=>'Sean Kingston', 'year'=>'2010');
 $song[]=array('title'=>'Love Your Enemy', 'singer'=>'Green Day', 'year'=>'1997');
 $song[]=array('title'=>'Gone', 'singer'=>'Kelly Clarkson', 'year'=>'1956');
 $song[]=array('title'=>'Know Your Enemy', 'singer'=>'Green Day', 'year'=>'1997');
 $song[]=array('title'=>'Gone long away', 'singer'=>'Kelly Clarkson', 'year'=>'1976');

 $find='belong me';
 $accepted=15; 
 $tmp=array();

 foreach($song as  $key => $value)
 { 
     similar_text(strtoupper($value['title']),  strtoupper($find), $p);
     if($p>=$accepted)
     $tmp[$p][] = 'title: '.$value['title'].' | rate: '.round($p,2).'%<br>'; 
 }
 krsort($tmp);

  echo 'THIS IS YOUR SEARCH RESULT FOR \'',$find,'\':<br>';
  echo '_____________________________________________________<br>';
  foreach($tmp as $key => $percentage)
    foreach($percentage as $value)
        echo $value ;

?> 
Melsi
  • 1,462
  • 1
  • 15
  • 21
  • Thanks for taking the time to come up with something, but I am unsure how to apply this code for what I am attempting to accomplish. I made a comment up above this answer to '@Frits van Campen' Please read it to further seek what I need. – Michael Ecklund Jun 20 '11 at 16:06