S
S
SpeakeazyYT12019-07-20 14:48:24
PHP
SpeakeazyYT1, 2019-07-20 14:48:24

How to check the identity of the article from two multidimensional arrays and if the articles from 2 arrays do not match, then perform the PHP action?

Good afternoon. There are 2 arrays:
1 (in which we are looking for):

Array
(
  [0] => Array(
    [PROPERTY_31_VALUE] => MTN6710-0004
  ),
  
  [1] => Array(
    [PROPERTY_31_VALUE] => HUHG3578-FU
  ),
  ...
)

2:
Array
(
  [0] => Array(
    [PROPERTY_22_VALUE] => FUGURNG24-0005
  ),
  
  [1] => Array(
    [PROPERTY_22_VALUE] => 93858FIHEJ-348
  ),
  ...
)

How to make a condition - if in each element of a multidimensional array (1) there is no match for the arial number from the array (2), then we perform an action (for example, count how many such elements are).
I have tried using the following code:
foreach ($arr1 as $arr1Item) {

  foreach ($arr2 as $arr2Item) {
    if ($arr2Item['PROPERTY_22_VALUE'] !== $arr1Item['PROPERTY_31_VALUE']) {
      $countElko[] = $arr2Item;
    }
  }
  
}

But there is one BUT, the result would be successful if the script reached the end, but it breaks on an out-of-memory error:
mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 533557248) (tried to allocate 536870920 bytes) in

How can this code be optimized?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Plotnikov, 2019-07-20
@kakisaebalsujit

Try like this

$do1 = '0';

foreahc ($arr1 as $arr1Item) {
    while (count($arr1) == $i) {
    	foreahc ($arr2 as $arr2Item) {
        	if ($arr1Item !== $arr2Item) {
        		$do = '1';
        		break;
        	}
        	i++;
      	}
    }
}


if ($do == '1') {
  //ваше действие
}

The idea should work)

S
Sergey c0re, 2019-08-01
@erge

You have both arrays represented as an array of arrays and the first key is a numeric index.
what if the new array does not store the elements of the $arr2 array, but the keys of non-matching elements.
In theory, it should take up much less space.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question