Hi

I have to find an array key exists in an array. My array structure is
$result (which is a result from a webservice).
Then I have to iterate the values of the in a foreach like

foreach($result['GetSessionListResult']['diffgram']['NewDataSet']['Table'] as $item).
{

}

. Ok Then my problem is sometimes webserice maynot have the out put. Then it only have result $result. This time my foreach will throw an undefined offset error. Then I put a isset checking like this.

if(isset($result['GetSessionListResult']['diffgram']['NewDataSet']['Table']))
{

}

But it shows the same error again. Then I google and found 'array_key_exists'. But I dont know how to use this in my case. Can anyone help me on this issue?

Instead of

if(isset($result['GetSessionListResult']['diffgram']['NewDataSet']['Table']))

use

if (array_key_exists('table',$result['GetSessionListResult']['diffgram']['NewDataSet']))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.