|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
i'm having a go at coding a simple, quick-n-dirty searchengine, which involves the similar_text() function. However, I can't seem to get it to calculate the percent-wise similarity between two variables. The manual states that to the syntax: int similar_text(string first, string second, double [percent]); adding the third argument as a 'reference' (what's that?) will calculate the similarity in percent. How would I get that value? Thanx in advance. Thomas, Denmark |
|
#2
|
|||
|
|||
|
Untested, but I think this is how it'd work:
$a = similar_text("bear", "bean", $b); After the function runs, $a would have the integer value '3' because there are 3 letters that are the same. $b would have the double-precision real number .75 (or maybe 75) because 3/4's of the letters match. What you're seeing is a sneaky way of getting a function to return two variables. |
|
#3
|
|||
|
|||
|
Yeah, that's exactly what I thought, however I never get a return value from $b - there's simply no output at all when i print the variable.
Any suggestions? Regards - Thomas |
|
#4
|
|||
|
|||
|
Do you mean, "pass by reference"?
To do so, place a & before the variable name. a_function (&$x) { } $y = a_function (&$z); --Chris |
|
#5
|
|||
|
|||
|
Thanx a bunch - that did the trick! And I even found it now in the manual. Kinda embarrasing now that you've provided the solution, but I was a bit confused about the reference-part that was a bit blurry methinks.
Anyway, thanks again and cheers. - Thomas |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Similar_text() syntax problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|