S
S
Sergey Beloventsev2018-02-07 21:28:02
PHP
Sergey Beloventsev, 2018-02-07 21:28:02

How to clean up arrays?

Eats two arrays for example

[
0=>52,
1=>45,
2=>58
]

and
[
38=>47,
78=>68
45=>85,
]

it is necessary to subtract from the second array the element whose key is equal to the value of the first in this example, this is the third element of the array whose key is 45

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-02-07
@slo_nik

Good evening.
Try starting with the following:

$a = ['0' => '52',
'1' => '45',
'2' => '58'];
$b = ['38' => '47',
'78' => '68',
'45' => '85'];
foreach ($b as $key => $value) {
  if(in_array($key, $a)){
       unset($b[$key]);
  }
}
print_r($b);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question