1

In the code here, i get an undefined index error using ternary operator.

here is the code :

$phone = isset($_POST['phone']) ? $_POST['phone'] 
        : isset($_GET['phone'])? $_GET['phone'] : null;

But, the posted array has the phone index as shown in the image(captured from VS Code ).

enter image description here

When I changed it to this,

if(isset($_POST['phone']))$phone =  $_POST['phone'];
else $phone = isset($_GET['phone']) ? $_GET['phone'] : null;

The code works fine. is it any error in my code? or is it not supported in ternary operator?

Prashanth Benny
  • 1,523
  • 21
  • 33
  • 1
    try wrapping the 'false' -> `$phone = isset($_POST['phone']) ? $_POST['phone'] : (isset($_GET['phone'])? $_GET['phone'] : null);` – Sean Jan 14 '19 at 05:02

0 Answers0