0

I have a json array returned from a validator thus:

{  "email":["Email must not be empty","Email must be valid email"],
   "password":["Password must not contain whitespace"],
   "rpassword":["Rpassword must not be empty"]
}

The data was returned from (an my aim is to get the first value "Email must not be empty" knowing well that 'email' must not always be the first object):

  $data = json_decode($datas, true);

 //echo $data[0][0]; // this is what was tried!
JSking
  • 399
  • 1
  • 4
  • 18
  • 1
    It creates an assoc array when decoded `echo $data['email'][0]; //outputs "Email must not be empty"` – IsThisJavascript Oct 19 '17 at 13:46
  • no way @WillParky93 – JSking Oct 19 '17 at 13:48
  • Did you mean to run `$data = json_decode($datas, true);` rather than `$data = json_encode($datas, true);`? If so; see this: https://3v4l.org/dED87 – IsThisJavascript Oct 19 '17 at 13:52
  • YES I mean json_decode($datas, true); – JSking Oct 19 '17 at 13:54
  • Ok, so as you can see it's `echo $data['email'][0];` gl and hf on your project – IsThisJavascript Oct 19 '17 at 13:56
  • @WillParky93 sometimes the 'email' will not be availalbe, my program will then want to get "Password must not contain whitespace" from the 'password' object – JSking Oct 19 '17 at 14:03
  • You must try yourself :) There's no fun in it if I do it all for you! You can check if email is set with `isset()` or empty with `empty()`. If you come across an issue that you cannot find a solution too even after doing research, then you can post another question. – IsThisJavascript Oct 19 '17 at 14:26

0 Answers0