0

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?

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by edwinhermann
0

Instead of

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

use

if (array_key_exists('table',$result['GetSessionListResult']['diffgram']['NewDataSet']))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.