How to find the key in multidimensional array using value in PHP

We are using the array PHP function to find a key in a multidimensional array using PHP

Example:

<?php
$offerData = array(
        "0"=>array(
            "id"=>'1',
            "user_id"=>'1',
            "service"=>'SAME_DAY',
            'sub_service'=>'Tesr',
            'from_zip'=>'395006'
            ),
        "1"=>array("id"=>'1',
            "user_id"=>'1',
            "service"=>'DOMESTIC',
            'sub_service'=>'Tesr',
            'from_zip'=>'395006'
            )
    );
$keySame = array_search("DOMESTIC", array_column($offerData, 'service'));
echo "Key Value is: " . $keySame;
?>

Output:

Key Value is: 1

I hope it will help you. 

Tags: