get index of json key using php
<p>I want to find index of key from json array similar to this question <a href="https://stackoverflow.com/questions/15218448/get-index-of-a-key-in-json">Get index of a key in json</a>
but i need the solution using php.</p>

<p>here is my json (partial data)</p>

<pre><code>{   
"currentOver":{
    "events":[]
},  
"matchString":"",
"currentPlayer":5, 
"previousOvers":[], 
"innings":[],   
"scorecards":[
    {
        "batting":{
            "players":[
                        {"id":16447,"name":"Rahul Roy"},
                        {"id":12633,"name":"Sijal Thomas"},
                        {"id":16446,"name":"Mohammed Reza"},
                        {"id":16509,"name":"Asif Khan"},
                        {"id":12633,"name":"Koyel Dijesh"},
                        {"id":16468,"name":"Shahrook"},
                        {"id":64691,"name":"Shafiq"},
                        {"id":6518,"name":"Ubaidulah"}
            ]
        }
    }
]

}
</code></pre>

<p>and php</p>

<pre><code>foreach ($read_json-&gt;scorecards-&gt;batting-&gt;players as $batsmen =&gt; $val) {    
                if($val == 5) {   // if batsman index is 5 then display his name
                    $name = $batsmen-&gt;name;

                    echo "&lt;div&gt;$name&lt;/div&gt;\n"; 

                }               
}
</code></pre>

<p>Please help me to solve this issue.Thanks in advance.</p>