-2

I have a MySQL table with a check column (active)

TABLE

ID    USER    ACTIVE
1     Mike    0
2     Mark    1
3     Paul    1
4     John    0

And results stored on Array

$check = array();
$query1 = mysql_query("SELECT * FROM mod_users");
while ($row = mysql_fetch_assoc($query1)) {
    $check[] = $row['active'];       
}

I need to check array results in a while cycle:

in_array($foo, $check)

Exist a way to allow duplicate keys for $check array?

Mark
  • 8,046
  • 15
  • 48
  • 78
user2307958
  • 349
  • 3
  • 14
  • 2
    Please take some time to read [this question and answer](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189). – Marty May 08 '13 at 01:29
  • You need to clarify your question. What is in $foo and why are you checking against the "active" column? Your code doesn't really make much sense as you're filling your array with non-unique values. – BrianS May 08 '13 at 01:36
  • 2
    Why check array results? You can filter them on your MySQL query by adding `WHERE ACTIVE = 1` (ACTIVE) OR `WHERE ACTIVE = 0`(INACTIVE). – Mark May 08 '13 at 01:36
  • 2
    Duplicate keys? Isn't a key unique by definition? – elclanrs May 08 '13 at 01:39
  • @elclanrs Normally keys are an index by default afaik. – Ja͢ck May 08 '13 at 01:45
  • Being that this is a non-associative array, the uniqueness of the keys shouldn't matter because they will simply be identified by their position in the array and will, in effect, be unique by default. So if you were to add two "active" values (0, 1) and dump your array, you'll get Array(2) { [0]=> int(0) [1]=> int(1) } – Michael O'Brien May 08 '13 at 01:47

1 Answers1

0

No. It does not make any sence.

You can use array_keys for check.

count(array_keys($check, $foo));

Or array_filter

count(array_filter($check, function($value)use($foo){return $value==$foo;}));
sectus
  • 15,605
  • 5
  • 55
  • 97