nzrubin
asked on
check if all items are in array php
hi guys
i want to check if one array contain all the items as second one has
$array_1 = "1,4,2,5";
$array_2 = "4,5,2";
if ($array_2 == $array_1)
{YES}
else
{NO}
thanks a lot!
[[ phpBB zone removed by PenguinMod, EE Moderator, per Q_23571807.html ]]
i want to check if one array contain all the items as second one has
$array_1 = "1,4,2,5";
$array_2 = "4,5,2";
if ($array_2 == $array_1)
{YES}
else
{NO}
thanks a lot!
[[ phpBB zone removed by PenguinMod, EE Moderator, per Q_23571807.html ]]
ASKER
sorry about phpbb
(i thought easier the question less i put points.....)
ill try to explain more: (you right)
i have two arrays for example
$array_1 = "1,4,2,5";
$array_2 = "4,5,2";
i want to compare two arrays to check if they have the same amount of values and the same values (even if they not in a right order). (values are always integers)
for example if arrays looks like below
$array_1 = "1,4,2,5";
$array_2 = "4,5,2,1";
if ($array_1 == $array_2)
{ echo "Done";}
(i thought easier the question less i put points.....)
ill try to explain more: (you right)
i have two arrays for example
$array_1 = "1,4,2,5";
$array_2 = "4,5,2";
i want to compare two arrays to check if they have the same amount of values and the same values (even if they not in a right order). (values are always integers)
for example if arrays looks like below
$array_1 = "1,4,2,5";
$array_2 = "4,5,2,1";
if ($array_1 == $array_2)
{ echo "Done";}
Try this:
<?php
function isArrayInArray($searchFor, $searchIn) {
foreach($searchFor as $key) {
$count += in_array($key,$searchIn);
}
return $count==sizeof($searchFor);
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it works with very minor adjustment
for ($i=0;$i<=count($array1);$ i++)
{
if(!$array1[$i]==$array2[$ i])
{
echo arrays dotn match;
break;
}
}
thanks
for ($i=0;$i<=count($array1);$
{
if(!$array1[$i]==$array2[$
{
echo arrays dotn match;
break;
}
}
thanks
second, for being a premium service member this is a low amount of points..(the higher the point value the quicker and more experts will come.)
third, your question doesn't explain what you want.. so please explain it more..