News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

Search inside array?

Started by margarett, October 23, 2007, 12:02:51 PM

Previous topic - Next topic

margarett

Hi all...

Imagine if I have this code:

if (($board = 1) && ($board = 2) && ($board = 3) && ($board = 4) && ($board = 5) && ($board = 6) && ($board = 7))


Can I create an array like:

$myarray = array(1, 2, 3, 4, 5, 6, 7);


And replace all those "board=xx" && "board=yy" for a "search function inside my array?

Thanks!
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

codenaught

Well that code doesn't really make sense because $board is only one value, in SMF at least. But perhaps you meant ||.

You can do something like:

$myarray = array(1, 2, 3, 4, 5, 6, 7);
if (in_array($board, $myarray))
{
   <do something when $board has its value inside of $myarray>
}

If comparing two arrays...

$arr1 = array(1, 2, 3, 4);
$arr2 = array(1, 5, 7, 9);

// Only need one value to be in both?
if (array_intersect($arr1, $arr2))
    <do something>;

// Need $x values to be in both?
if (count(array_intersect($arr1, $arr2)) >= $x)
    <do something>;
Dev Consultant
Former SMF Doc Coordinator

Advertisement: