Prashant Kumbhar Prashant Kumbhar - 7 months ago 46
MySQL Question

How to Store Array in Mysql Using PHP

I want to store array in mysql database. with key and value

Following are code i used

$name= "prashant";
$lname= "kumbhar";
$test = "testing";

$array = ('fname'=>$name,
'test' = $testing

Store these $array in database using php


Use json_encode() to store data in mysql table.

$name= "prashant";
$lname= "kumbhar";
$test = "testing";

$array = array('fname'=>$name,
               'test' => $test

$res = json_encode($array);
echo "Convert from array to json :" .$res;

echo "\n\nFrom json to array:\n";


Convert from array to json :

From json to array:
stdClass Object
    [fname] => prashant
    [lname] => kumbhar
    [test] => testing

At the time of retrieve data in array form then use json_decode()

Working Demo : Click Here