Search code examples
phparraysstringassociative

convert string array to array php


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


Solution

  • 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