php - Search in multidimensional array -
On my website I have a list of products generated through a this is the array: (small) I need to search within this multi-dimensional array if the In short, I do not want to define the array of 2 products the same : The array of products is the Universe but the product should work: Keeps an array of added models and if not already unset. Updated your updated code: Update to improve performance by Ryan: foreach and a multi-dimensional Array creates
["model"] repeats
["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 '])); }
$ 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 +; }
$ 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); }
$ 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
Post a Comment