php - Search in multidimensional array -


On my website I have a list of products generated through a foreach and a multi-dimensional Array creates

this is the array: (small)

I need to search within this multi-dimensional array if the ["model"] repeats

In short, I do not want to define the array of 2 products the same ["model"]

:

 < code> foreach ($ result as a result result) {$ this- & gt; Data ['product'] [] = array ('product_id' = & gt; $ result ['product_id'], 'model' = & gt; $ corto, 'thumb' => $ image, 'Disponibilidad' = & gt; $ rstock, 'name' = & gt; $ nombre, 'description' => utf8_substr (strip_tags (html_entity_decode ($ result ['description'], ENT_QUOTES, '' UTF-8 ')), 0, $ '[' $ ',' Special '=> $ special,' tax '=> $ tax,' rating '= & gt; $ result [' rating ' ], 'Review' = & gt; sprintf ($ -> get-> this-> language-> ('text_overview'), (int) $ result ['review']), 'href' = & gt; ; $ This-> url- & gt; Link ('product / product', 'path ='. $ This- & gt; request- & g get; ['path']. & Amp; product_id = '. $ result [' product id '])); }     

The array of products is the Universe but the product should work:

  $ products // Here your product array $ model = array (); $ count = 0; Foreign currency ($ products as products $) {// if the model exits (unset / remove from array) if (in_array ($ product ['model'], $ model) set ($ products [$ Count]); // Add the model number in array array_push ($ model, $ product ['model']); // Calculate Count $ count +; }   

Keeps an array of added models and if not already unset.

Updated your updated code:

  $ model = array (); Foreign exchange ($ result as result of $) {// If the model turns out, check that (in_array ($ corto, $ model)) is in progress; $ the-> data- 'product' '= & gt; $ rstock, 'name' = & gt; $ Nombre, 'description' = & gt; utf8_substr (strip_tags (html_entity_decode ($ result ['description'], ENT_QUOTES, 'UTF-8')), 0, 100) $ 'value,' special '= & gt; $ Special, 'tax' = & gt; $ Tax, 'rating' = & gt; $ Result ['rating'], 'review' = & gt; Sprintf ($ this-> Get Language-> ('text_reviews'), (int) $ result ['review']), 'href' = & gt; $ This- & gt; url-> Get the link ('product / product', 'path ='. $ This-> request-> ['path']. & Amp; product_id = '. $ Result [' product_id '])); // Add model to array array_push ($ model, $ corto); }    

Update to improve performance by Ryan:

  $ model = array (); Foreign exchange ($ result as result of $) {// Check if the model turns out (isset ($ model $ corto)); $ This- & gt; Data ['product'] [] = array ('product_id' = & gt; $ result ['product_id'], 'model' = & gt; $ corto, ..... 'href' = & gt; $ this - & gt; url- & gt; Link ('product / product', 'path ='. $ this- & gt; request-> [path ']]. & amp; product_id ='. $ result ['Product_id'])); // Add model for array $ model [$ corto] = true; }    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -