bemdev
@bemdev

Как правильно перебирать и убирать дубли в массиве php?

Приветствую, подскажите пожалуйста как правильно работать с массивами в php.

есть массив
stdClass Object ( [virtuemart_manufacturer_id] => Array ( [0] => 1 ) [mf_name] => CarLine [slug] => logika-budilnik-moe-vremya-so-svetom-i-zvukom-na-batarejkakh-v-korobke [mf_email] => [mf_desc] => [virtuemart_manufacturercategories_id] => 0 [mf_url] => [published] => 1 [_lhash:VmTable:private] => a8a00e77a80745b8fa959a76a29edcb2 [_tbl:protected] => #__virtuemart_products [_tbl_lang:protected] => #__virtuemart_products_ru_ru [_tbl_key:protected] => virtuemart_product_id [_tbl_keys:protected] => Array ( [0] => virtuemart_product_id ) [_pkey:protected] => virtuemart_product_id [_pkeyForm:protected] => cid [_obkeys:protected] => Array ( [product_name] => 1 [slug] => 1 ) [_unique:protected] => 1 [_unique_name:protected] => Array ( [slug] => 1 ) [_orderingKey:protected] => ordering [_slugAutoName:protected] => product_name [_slugName:protected] => slug [_db:protected] => JDatabaseDriverMysqli Object ( [name] => mysqli [nameQuote:protected] => ` [nullDate:protected] => 0000-00-00 00:00:00 [_database:JDatabaseDriver:private] => newshop [connection:protected] => mysqli Object ( [affected_rows] => 29 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 10 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.25 [server_version] => 50525 [stat] => Uptime: 24954 Threads: 1 Questions: 91379 Slow queries: 0 Opens: 39494 Flush tables: 1 Open tables: 4 Queries per second avg: 3.661 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 280 [warning_count] => 0 ) [count:protected] => 65 [cursor:protected] => [debug:protected] => [limit:protected] => 0 [log:protected] => Array ( ) [timings:protected] => Array ( ) [callStacks:protected] => Array ( ) [offset:protected] => 0 [options:protected] => Array ( [driver] => mysqli [host] => localhost [user] => root [password] => [database] => newshop [prefix] => j3_ [select] => 1 [port] => 3306 [socket] => ) [sql:protected] => SELECT `jmmod`.`module_id`, `module_name`, `module_perms`, `id`, `name`, `link`, `depends`, `icon_class`, `view`, `task`FROM `#__virtuemart_modules` AS jmmod LEFT JOIN `#__virtuemart_adminmenuentries` AS item ON `jmmod`.`module_id`=`item`.`module_id` WHERE jmmod.published='1' AND item.published='1' ORDER BY `jmmod`.`ordering`, `item`.`ordering` [tablePrefix:protected] => j3_ [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [transactionDepth:protected] => 0 [disconnectHandlers:protected] => Array ( ) ) [_rules:protected] => [_trackAssets:protected] => [_locked:protected] => [_loggable:protected] => 1 [_xParams] => product_params [_varsToPushParam] => Array ( [min_order_level] => Array ( [0] => [1] => float ) [max_order_level] => Array ( [0] => [1] => float ) [step_order_level] => Array ( [0] => [1] => float ) [product_box] => Array ( [0] => [1] => float ) ) [_translatable] => 1 [_translatableFields:protected] => Array ( [0] => product_name [1] => product_s_desc [2] => product_desc [3] => metadesc [4] => metakey [5] => customtitle [slug] => slug ) [_cryptedFields] => [_langTag:protected] => ru_ru [_ltmp] => [_loaded] => 1 [_updateNulls:protected] => 1 [_tablePreFix] => p. [_autoincrement] => 1 [_observers] => JObserverUpdater Object ( [observers:protected] => Array ( ) [doCallObservers:protected] => 1 ) [created_on] => 2016-02-23 11:46:37 [created_by] => 42 [modified_on] => 2016-11-26 08:28:22 [modified_by] => 45 [virtuemart_product_id] => 99 [virtuemart_vendor_id] => 1 [product_parent_id] => 0 [product_sku] => 0015e588-aed4-11e5-acf6-5cf3fc796adc [product_room] => Магазин Бегемотик (ТЦ Город, 5 Этаж) [product_spe] => [product_gtin] => [product_mpn] => [product_name] => Логика Будильник Мое время со светом и звуком, на батарейках, в коробке [product_s_desc] => [product_desc] => [product_weight] => 0.0000 [product_weight_uom] => KG [product_length] => 0.0000 [product_width] => 0.0000 [product_height] => 0.0000 [product_lwh_uom] => M [product_url] => [product_in_stock] => 3 [product_ordered] => 0 [low_stock_notification] => 0 [product_available_date] => 0000-00-00 00:00:00 [product_availability] => [product_special] => 0 [pordering] => 0 [product_sales] => 0 [product_unit] => KG [product_packaging] => 0.0000 [product_params] => min_order_level=""|max_order_level=""|step_order_level=""|product_box=""| [intnotes] => [customtitle] => [metadesc] => [metakey] => [metarobot] => [metaauthor] => [layout] => 0 [min_order_level] => [max_order_level] => [step_order_level] => [product_box] => [allIds] => Array ( ) [virtuemart_media_id] => Array ( [0] => 4377 ) [shoppergroups] => [allPrices] => Array ( [0] => Array ( [virtuemart_product_price_id] => 12159 [virtuemart_product_id] => 99 [virtuemart_shoppergroup_id] => 0 [product_price] => 799.000000 [override] => 0 [product_override_price] => 0.00000 [product_tax_id] => 0 [product_discount_id] => 0 [product_currency] => 131 [product_price_publish_up] => 0000-00-00 00:00:00 [product_price_publish_down] => 0000-00-00 00:00:00 [price_quantity_start] => 0 [price_quantity_end] => 0 [created_on] => 2016-02-23 11:46:37 [created_by] => 42 [modified_on] => 2016-04-05 10:35:08 [modified_by] => 42 [locked_on] => 0000-00-00 00:00:00 [locked_by] => 0 ) ) [selectedPrice] => 0 [categoryItem] => Array ( [0] => Array ( [virtuemart_category_id] => 661 [virtuemart_vendor_id] => 1 [category_name] => Игрушки интерактивные и др [slug] => igrushki-interaktivnye-i-dr [category_description] => [category_template] => 0 [category_layout] => 0 [category_product_layout] => 0 [products_per_row] => 0 [ordering] => 0 [shared] => 0 [limit_list_step] => 0 [limit_list_initial] => 0 [metadesc] => [customtitle] => [metakey] => [metarobot] => [metaauthor] => [published] => 1 [VmTable_lhash] => 5f85a7815d89ea22264bcad2070854a5 [*_tbl] => #__virtuemart_categories [*_tbl_lang] => #__virtuemart_categories_ru_ru [*_tbl_key] => virtuemart_category_id [*_tbl_keys] => Array ( [0] => virtuemart_category_id ) [*_pkey] => virtuemart_category_id [*_pkeyForm] => cid [*_obkeys] => Array ( [category_name] => 1 [slug] => 1 ) [*_unique] => 1 [*_unique_name] => Array ( [slug] => 1 ) [*_orderingKey] => ordering [*_slugAutoName] => category_name [*_slugName] => slug [*_db] => JDatabaseDriverMysqli Object ( [name] => mysqli [nameQuote:protected] => ` [nullDate:protected] => 0000-00-00 00:00:00 [_database:JDatabaseDriver:private] => newshop [connection:protected] => mysqli Object ( [affected_rows] => -1 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 10 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.25 [server_version] => 50525 [stat] => Uptime: 24954 Threads: 1 Questions: 91379 Slow queries: 0 Opens: 39494 Flush tables: 1 Open tables: 4 Queries per second avg: 3.661 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 280 [warning_count] => 0 ) [count:protected] => 65 [cursor:protected] => [debug:protected] => [limit:protected] => 0 [log:protected] => Array ( ) [timings:protected] => Array ( ) [callStacks:protected] => Array ( ) [offset:protected] => 0 [options:protected] => Array ( [driver] => mysqli [host] => localhost [user] => root [password] => [database] => newshop [prefix] => j3_ [select] => 1 [port] => 3306 [socket] => ) [sql:protected] => SELECT `jmmod`.`module_id`, `module_name`, `module_perms`, `id`, `name`, `link`, `depends`, `icon_class`, `view`, `task`FROM `#__virtuemart_modules` AS jmmod LEFT JOIN `#__virtuemart_adminmenuentries` AS item ON `jmmod`.`module_id`=`item`.`module_id` WHERE jmmod.published='1' AND item.published='1' ORDER BY `jmmod`.`ordering`, `item`.`ordering` [tablePrefix:protected] => j3_ [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [transactionDepth:protected] => 0 [disconnectHandlers:protected] => Array ( ) ) [*_rules] => [*_trackAssets] => [*_locked] => [*_loggable] => 1 [_xParams] => 0 [_varsToPushParam] => Array ( ) [_translatable] => 1 [*_translatableFields] => Array ( [0] => category_name [1] => category_description [2] => metadesc [3] => metakey [4] => customtitle [slug] => slug ) [_cryptedFields] => [*_langTag] => ru_ru [_ltmp] => [_loaded] => 1 [*_updateNulls] => [_tablePreFix] => c. [_autoincrement] => 1 [_observers] => JObserverUpdater Object ( [observers:protected] => Array ( ) [doCallObservers:protected] => 1 ) [created_on] => 0000-00-00 00:00:00 [created_by] => 0 [modified_on] => 2016-02-23 17:19:16 [modified_by] => 42 [id] => 2235 ) ) [canonCatId] => 661 [categories] => Array ( [0] => 661 ) [virtuemart_category_id] => 661 [ordering] => 0 [id] => 2235 [category_name] => Игрушки интерактивные и др [mediaitems] => 1 [reviews] => 0 [product_price_display] => 799 руб. [categoriesList] => Игрушки интерактивные и др [manuList] => CarLine )


это как бы один из элементов большого массива [0] позиция так сказать.

так вот как мне пройти по большому массиву и поле productlist сделать как бы уникальным, по сути там разные записи с одним guid мне надо как то оставить одну уникальную.
  • Вопрос задан
  • 237 просмотров
Пригласить эксперта
Ответы на вопрос 2
Hakkunamatata
@Hakkunamatata
Зефирный-человек
Цикл + новый массив

$uniqObjects = [];
foreach ($notUniqObjects as $object) {
    foreach ($uniqObjects as $uniqObject) {
        if ($uniqObject->targetProperty == $object->targetProperty) {
            continue 2;
        }
    }

    $uniqObjects[] = $object;
}
Ответ написан
ravshanium
@ravshanium
аналитик, веб-программист
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы