-9

I have an array in string given below.

$string="
"Status":true,
"ReVerifiedCount":1,
"ProfilePrefix":"INVTRK"
";

How I can get array from this string same as it exists in string.

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
Waleed Ali
  • 21
  • 1
  • 5
  • 3
    This code is absolute garbage, it will never work because you're using quotes inside quotes of an object. Do you know what you are doing? If you want to change the JSON object (which it looks like), you should read more about `json_encode`, `json_decode` and everything about PHP at all, as I can see now. – Franky W. Nov 13 '17 at 08:13

2 Answers2

1
<?php

$string='{
"Status":true,
"ReVerifiedCount":1,
"ProfilePrefix":"INVTRK"
}';

$data=json_decode($string,true);
print_r($data);

I formated your string-json the right way. Your double quotes and the missing brackets were creating the main problem as your input was not a valid json.

Output is this:

Array ( [Status] => 1 [ReVerifiedCount] => 1 [ProfilePrefix] => INVTRK )
pr1nc3
  • 8,108
  • 3
  • 23
  • 36
0

First your String looks like a json string.

$string='{
"Status":true,
"ReVerifiedCount":1,
"ProfilePrefix":"INVTRK"
}';

This is the correct form.

To parse it use json_decode from PHP

$parsedArray = json_decode($string, true);

Here is a link to the doc : http://php.net/manual/en/function.json-decode.php

schieben
  • 78
  • 1
  • 8
  • I suggest when you decode to use ,true in order to get an array, or else you get stdclass object which can not be parsed as easy as an array. – pr1nc3 Nov 13 '17 at 08:37