1

I am putting an array ($row) in another array ($allRows):

array_push($allRows, $row);

Is there an easy way to check if an array already exists in $allRows?

1
  • What do you mean? array_intersect? Commented May 30, 2012 at 12:47

4 Answers 4

2

Yes:

if (in_array($array1, $array2)) {
echo "Array found";
}
// $array1 - needle.
Sign up to request clarification or add additional context in comments.

1 Comment

That does the trick, thanks! Perfect...didnt know that in_array can do that.
1

This is possible with in_arrayDocs:

if (in_array($row, $allRows, TRUE)) {
   echo "Array found";
}

In difference to the existing answer, this one actually tells you the order of parameters and that it's necessary that you specify the strict parameter.

Otherwise you would be comparing something else which most likely is not what you're looking for, see Comparison OperatorsDocs.

Comments

0

Use in_array()...

$range = range(1, 10);

var_export(in_array($range, array(range(1, 10))));

CodePad.

Comments

0

You can check if $allRows already have elements with

count($allRows)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.