-1

I have 2 multidimensional array

array1

0 => array (105, 44, 20, 0)
1 => array (106, 44, 21, 2)
2 => array (107, 45, 20, 0)

array2

0 => array (124, 44, 20, 1)
1 => array (105, 44, 20, 0)
2 => array (107, 45, 20, 0)

And now I need to find if elements from array1 are in array2 without changes.

I need create array1, then user change some values in array, remove some arrays, or reorder it. It will create array2. And after that I need compare if array from array1[0] with all his values exists in array2, and do it for all elements in array1. If element from array1 is the same in array2 I will save it to db. If element was removed and is not located in array2, or some values was changed I need delete it from db. thanks a lot

scooti
  • 51
  • 1
  • 7
  • Show us some code please – Lino Dec 14 '15 at 14:55
  • Possible duplicate of [php check if array contains all array values from another array](http://stackoverflow.com/questions/9655687/php-check-if-array-contains-all-array-values-from-another-array) – Pardeep Dhingra Dec 14 '15 at 14:59

2 Answers2

0

I didn't figure your case, but I think you are asking about this:

$array1=array(0 => array (105, 44, 20, 0),
1 => array (106, 44, 21, 2),
2 => array (107, 45, 20, 0));

$array2 = array(0 => array (124, 44, 20, 1),
1 => array (105, 44, 20, 0),
2 => array (107, 45, 20, 0));

for($i = 0; $i < sizeof($array1); $i++){


    for($j = 0; $j < sizeof($array2); $j++){


        if(empty(array_diff($array1[$i], $array2[$j])))

            die("exist"); // so array1[$i] exist in array2
    }
}
Mohammad
  • 3,449
  • 6
  • 48
  • 75
0
$index1 = 0
$index2 = 0

foreach ($array1 as $value1)
{
    $index1++;
    foreach ($array2 as value2)
    {
        if (!empty(array_diff ($value1, $value2))
            // $array[$index1] !== $array[$index2]
        else
            // $array[$index1] == $array[$index2]

        $index2++;
    }
}
Valérian Polizzi
  • 453
  • 1
  • 4
  • 10