<?php
class VerifyInArray
{
public function getMyCollection($field, $collection)
{
if (count($collection)) { foreach ($collection as $k => $val) {
$list[] = $val[$field];
}
}
return $list;
}
public function inMyArray($collection, $field, $findValue)
{
if (isset($collection[0])) { return 'no';
}
}
if (in_array($findValue, $this->getMyCollection($field, $collection))) { return 'ok';
}
return 'no';
}
public function displayInArray($collection, $attr, $value)
{
return 'search result: '. $this->inMyArray($collection, $attr, $value);
}
}
$src = new VerifyInArray();
'ID' => 1,
'name' => 'Smith'
),
'ID' => 2,
'name' => 'John'
)
);
echo $src->displayInArray($collection, 'ID', 2). "\n<br>" .
$src->displayInArray($collection, 'ID', 0);
PD9waHAKCmNsYXNzIFZlcmlmeUluQXJyYXkKewogcHVibGljIGZ1bmN0aW9uIGdldE15Q29sbGVjdGlvbigkZmllbGQsICRjb2xsZWN0aW9uKQogewogICAgICRsaXN0ID0gYXJyYXkoKTsKICAgICBpZiAoY291bnQoJGNvbGxlY3Rpb24pKSB7CiAgICAgICAgZm9yZWFjaCAoJGNvbGxlY3Rpb24gYXMgJGsgPT4gJHZhbCkgewogICAgICAgICAgICAkbGlzdFtdID0gJHZhbFskZmllbGRdOwogICAgICAgIH0KICAgICB9CiAgICAgcmV0dXJuICRsaXN0OwogfQogICAgCnB1YmxpYyBmdW5jdGlvbiBpbk15QXJyYXkoJGNvbGxlY3Rpb24sICRmaWVsZCwgJGZpbmRWYWx1ZSkKewogICAgaWYgKGlzc2V0KCRjb2xsZWN0aW9uWzBdKSkgewogICAgICAgIGlmIChhcnJheV9rZXlfZXhpc3RzKCRmaWVsZCwgJGNvbGxlY3Rpb25bMF0pID09IGZhbHNlKSB7CiAgICAgICAgICAgcmV0dXJuICdubyc7CQogICAgICAgIH0KICAgIH0KICAKICAgIGlmIChpbl9hcnJheSgkZmluZFZhbHVlLCAkdGhpcy0+Z2V0TXlDb2xsZWN0aW9uKCRmaWVsZCwgJGNvbGxlY3Rpb24pKSkgewogICAgICAgIHJldHVybiAnb2snOwogICAgfQogICAgcmV0dXJuICdubyc7Cn0KCnB1YmxpYyBmdW5jdGlvbiBkaXNwbGF5SW5BcnJheSgkY29sbGVjdGlvbiwgJGF0dHIsICR2YWx1ZSkKewogICByZXR1cm4gJ3NlYXJjaCByZXN1bHQ6ICcuICR0aGlzLT5pbk15QXJyYXkoJGNvbGxlY3Rpb24sICRhdHRyLCAkdmFsdWUpOwp9Cgp9CiRzcmMgPSBuZXcgVmVyaWZ5SW5BcnJheSgpOwoKICRjb2xsZWN0aW9uID0gYXJyYXkoCiAgICAgICAgIGFycmF5KAogICAgICAgICAgICAgICAnSUQnID0+IDEsIAogICAgICAgICAgICAgICAnbmFtZScgPT4gJ1NtaXRoJwogICAgICAgICApLCAKICAgICAgICAgYXJyYXkoCiAgICAgICAgICAgICAgICdJRCcgPT4gMiwgCiAgICAgICAgICAgICAgICduYW1lJyA9PiAnSm9obicKICAgICAgICAgKQogICAgKTsKZWNobyAkc3JjLT5kaXNwbGF5SW5BcnJheSgkY29sbGVjdGlvbiwgJ0lEJywgMikuICJcbjxicj4iIC4KICAgICAkc3JjLT5kaXNwbGF5SW5BcnJheSgkY29sbGVjdGlvbiwgJ0lEJywgMCk7