0

at the moment I do something like this

exec($command, $retval);

The response is normally an array, which has either the value success or failure. At the moment, I am doing something like the following

if($retval[0] === 'success') {
    //do something else
} else {
   //handle the error
}

I have noticed though that sometimes, I see an error in the console which states

Undefined offset: 0 in

I presume that sometimes something is happening and an array is not returned. It is executing a Python script.

Is there any way I can handle if the offset is 0? I would have presumed this would have been handled in the else clause, but apparently not.

Thanks

1
  • 5
    if(isset($retval[0]) && $retval[0] === 'success') { do what ever you want } Commented Nov 20, 2015 at 13:44

1 Answer 1

2

You could handle the case using an isset() like so, as @Basheer Ahmed also pointed out above in a comment :

if( isset( $retval[0] ) && $retval[0] === 'success' ) {
    //do something else
} else {
   //handle the error
}
Sign up to request clarification or add additional context in comments.

Comments

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.