Save array in mysql database

前端 未结 6 1309
刺人心
刺人心 2020-11-29 03:17

I want to save extra information before sending the total order to Paypal. For each item I have created a single column in my MySQL database where I want to store it. Now I

6条回答
  •  抹茶落季
    2020-11-29 04:05

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

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

    $string will now hold a string version of the array. The output of the above code is as follows:

    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 );
    

提交回复
热议问题