1

I have string like this

{"status":"2","holding":"","company":"Company","nik":"8981237","name":"Markonah","ownercard":"Istri"}

how to convert this string to associative array in PHP

1 Answer 1

11

Its JSON, to convert to array use json_decode():

$string = '{"status":"2","holding":"","company":"Company","nik":"8981237","name":"Markonah","ownercard":"Istri"}';
$my_array = json_decode($string,true);
echo $my_array["status"]; // output: 2
Sign up to request clarification or add additional context in comments.

3 Comments

Probably better to perform a var_dump($my_array) or print_r($my_array) to allow the OP to see the complete array. Also json_decode returns an object so you would use $my_array->status. And you are missing a ; semi-colon on the end of $string.
To return an associative array you would use json_decode($string, true); Reference: php.net/manual/en/function.json-decode.php
@AhmadSopian If this solved your issue, please click the 'checkmark' to accept this answer.

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.