Antivirus
11-10-2008, 06:02 PM
I am wondering if there is an easier way to do the following than the way I have approached this, and if so would someone please share?
I have two string variables:
$owned = '1,5,22';
$opted = '1,2,7';
What I need to do here is return true if one of the numbers in $opted matches one of the numbers in $owned.
The way I am doing this check is as follows:
1) exploding both $owned and $opted
2) while looping through $ownedarray do a check for value in $opted array using in_array($value, $opted)
// Build the Opted-In stuff
$ownedarray = explode(",", $owned);
$optedarray = explode(",", $opted);
$sc_optedingroups = '';
foreach ($ownedarray AS $key => $val)
{
if (in_array($val, $optedarray))
{
$sc_optedingroups .= $vbulletin->sc_sgcache[$val]['name'] . ', ';
}
}
Is there another way, or easier way using some arcane php function which does this type of comparison without having to explode then loop the arrays as I have done above?
thanks :)
I have two string variables:
$owned = '1,5,22';
$opted = '1,2,7';
What I need to do here is return true if one of the numbers in $opted matches one of the numbers in $owned.
The way I am doing this check is as follows:
1) exploding both $owned and $opted
2) while looping through $ownedarray do a check for value in $opted array using in_array($value, $opted)
// Build the Opted-In stuff
$ownedarray = explode(",", $owned);
$optedarray = explode(",", $opted);
$sc_optedingroups = '';
foreach ($ownedarray AS $key => $val)
{
if (in_array($val, $optedarray))
{
$sc_optedingroups .= $vbulletin->sc_sgcache[$val]['name'] . ', ';
}
}
Is there another way, or easier way using some arcane php function which does this type of comparison without having to explode then loop the arrays as I have done above?
thanks :)