When working with arrays its necessary to store an array in a MySQL field. Unfortunately, there is no way to directly pass in an array as a parameter..

in this case we have to use the function serialize and unserialize in php

To convert any array (or any object) into a string using PHP, call the serialize function:

$array = array( 1, 2, 3 );
$string = serialize( $array );
echo $string;

this will results in

a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}

to convert back from the string to the array, use unserialize:

// $array will contain ( 1, 2, 3 )
$array = unserialize( $string );

This is how we can store Arrays in Database Php

Leave a Reply

Your email address will not be published. Required fields are marked *