H
H
hyget2018-03-15 14:17:57
PHP
hyget, 2018-03-15 14:17:57

Create array when comparing 2D array to 1D array?

Hello.
there is an array A:

$A[0]['url']='http://google.com/';
$A[0]['title']='Google';
$A[1]['url']='http://yandex.com/';
$A[1]['title']='Yandex';

and array B:
$B[0]="http://yandex.com";
$B[1]="http://yahoo.com"

It is necessary to form the 3rd array based on array A, only excluding the elements included in array B.
That is, in this example, in array C: should remain:
$С[0]['url']='http://google.com/';
$С[0]['title']='Google';

Help plz, I tried it myself through a nested loop
for($i=0; $i < count($A);$i++){
    for($j=0; $j<count($B);$j++){

but it does not work, if anyone knows, please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-03-15
@hyget

$c = [];
foreach($a as $one_a){
    if(in_array($one_a['url'],$b)){
        $c[] = $one_a;
    }
}
print_r($c);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question