S
S
smoln2018-04-22 13:07:01
PHP
smoln, 2018-04-22 13:07:01

How to merge two arrays, one obtained from the database, the other via api?

There is an array code received via api

$result_1 = $client->FindCatalog (array("ShortNumberDetail"=>$search));
                            $items = $result_1->FindCatalogResult->SearchedTheCatalog;
                            //Проверка один элемент или несколько, если один то он возвращается объектом, а не массивом
              
              //print_r($items);
              
                            if (count($items) > 1) {
                                foreach ($items as $item) {
                                    catalogTblRowCreate($item, $search,$client);
                                }
                            } else {
                                if (count($items) != 0) {
                                    catalogTblRowCreate($items, $search,$client);
                                } 
                            }



function catalogTblRowCreate($item, $searchCat,$client) {

  $result2 = $client->GetPriceId(array("ID"=>$item->id, "FormatCurrency" => 'РУБ', "SearchCross"=>0,"IdArticleDetail"=>null));
     $items_id = $result2->GetPriceIdResult->BasePriceForClient;
  //print "<pre>";
  //print_r($items_id);
  //	print "</pre>";
          if (count($items_id) > 1) {
                                        foreach ($items_id as $item) {
                                            detailsTblRowCreate($item);
                                        }
                                    } else {
                                        if (count($items_id) != 0) {
                                            detailsTblRowCreate($items_id);
                                        }
                                    }

}//catalogTblRowCreate

Accordingly, you need to combine the $items_id and $myrow array (the array obtained from the database) and, if possible, reduce the code for getting the $items_id array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ice, 2018-04-22
@IceRD

array_uintersect - php.net/manual/ru/function.array-uintersect.php
array_udiff - php.net/manual/ru/function.array-udiff.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question