Roi Patrick Florentino Roi Patrick Florentino - 1 month ago 4
PHP Question

Convert a string into a specified array using php

How can I convert into an array into a specified array to be exact.
Here's my string

data={"table":"users","fname":"mil","lname":"minoza","cntct":"09876543212"}


What I'm trying to achieve is something like this..

Array (
[table] => users
[fname] => mil
[lname] => minoza
[cntct] => 09876543212
)

Answer

Try with this:

$input = 'data={"table":"users","fname":"mil","lname":"minoza","cntct":"09876543212"}';
$data = str_replace('data=', $input);
$data = json_decode(input , true);