Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A high level overview should be like this:</p> <ul> <li>create the end result array $items</li> <li>loop through all the found items in all the websites</li> <li>for each one, check if it's similar enough to any of the existing item names in $items</li> <li>if yes, then add the price to that key, if no then create a new one and add it there</li> </ul> <p>Instead of <code>similar_text()</code> you should consider using <code>levenshtein()</code> which is similar in practice but quite faster.</p> <p>Here's some (untested, on the spot) code:</p> <pre><code>$levThreshold = 3 ; $_Prices = array() ; foreach ($_Retreived as $website =&gt; $websiteItems) { $currName = $websiteItems[0] ; $currWebsite = $websiteItems[1] ; $currPrice = $websiteItems[2] ; $foundItemKey = false ; //check current price structure. Get $priceData by reference //so we can modify it in the loop and keep the changed instead //of the loop copy. foreach ($_Prices as &amp;$priceData) { if (isset($priceData[$website])) { //already done this continue ; } //check if this is the item name we are looping over $lev = levenshtein($priceData['Name'], $currName) ; if ($lev &lt; $levThreshold) { //item exists, add price and break $priceData[$website] = $currPrice ; $foundItemKey = true ; break ; } } //if we haven't found the item key, create a new one if (!$foundItemKey) { $newItem = array() ; $newItem['Name'] = $currName ; $newItem[$website] = $currPrice ; $_Prices[] = $newItem ; } } </code></pre> <p><code>$levThreshold</code> is the minimum number of characters that must be different between 2 strings for them to be considered different. You can tweak that accordingly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload