0

I have a multi dimensional array and i want to use php array_search to find the key for where 2 key values match. below is my array.

    $array[] = [
        'id' => 2,
        'title' => 'product 2',
        'size' => 2
    ];

    $array[] = [
        'id' => 2,
        'title' => 'product 2',
        'size' => 1
    ];
$key = array_search(2, array_column($array, 'id'));

In the above case i get a $key value of 0 but the key value i want to get is 1. if is possible i want to use array_search to find where id=>2 and size=>1 in $array. Any help will be appreciated thanks.

1 Answer 1

3

Why not use foreach?

foreach ($array as $row) {
    if ($row['id'] === 2 && $row['size'] === 1) {
         //found
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

didn't use foreach because i was thinking there was a way but i guess i would have to go with that... thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.