-1

this is my array:

$array = array
(
    array
    (
        'id' => '1',
        'name' => 'Product 1',
        'qty' => '2'
    ),
    array
    (
        'id' => '2',
        'name' => 'Product 2',
        'qty' => '1'
    )   
);

i want get if there is the id value 1 return true, else return false. But it's only check base on id.

the problem is, how to check if the value of id is exist

1 Answers1

0
$key = array_search(1, array_column($array, 'id'));

it will return the key.

There are a lot of user comments in the PHP docs that can help you with questions such as this, see the below link.

http://www.php.net/manual/en/function.array-search.php#1069044.2k

スージン
  • 143
  • 8