I have a problem in using of array as a variable in nested if..else.. conditions. Its used to create custom web-service APIs. Here is the structure of code:
if (condition) {
// code to be executed in case of true
if (condition) {
// code to be executed in case of true
$result['key1'] = $variable1;
$result['key2'] = $variable2;
$result['key3'] = $variable3;
} else {
// code to be executed in case of false
}
} else {
$result['error'] = 'Something went wrong!!!';
}
echo json_encode($result); // line 121
On execution of code it displays the following error:
Notice: Undefined variable: result in C:\xampp.. on line 121