note 125682 deleted from function.levenshtein by cmb

From: Date: Fri, 15 Jan 2021 12:11:33 +0000
Subject: note 125682 deleted from function.levenshtein by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216163@lists.php.net to get a copy of this message
Note Submitter: phpcoder at gmail dot com ---- @Digeridoo $levenshtein = levenshtein($a, $b/*, 1, 1, 1*/); The easiest way (the one with minimum cost) to convert "1 apple" to "2 apples" is to replace "1" with "2" (at a cost of 1), and then insert an "s" (at a cost of 1). The total cost is therefore 2. $inserts = levenshtein($a, $b, 1, 0, 0); Again, we replace "1" with "2" and insert an 's'. The insertion has a cost of 1, and the replacement has a cost of 0; the total cost is 1. $deletes = levenshtein($a, $b, 0, 0, 1); Replacing "1" with "2" has zero cost, and so does inserting an "s"; the total cost of converting "1 apple" to "2 apples" is 0. $replaces = levenshtein($a, $b, 0, 1, 0); Easiest thing to do here is just delete everything and insert all-new text. Both have zero cost, so the total cost is 0.

« previous php.notes (#216163) next »