我想转换我的数组值:
Array ( [page_1] => fifth [page_2] => first [page_3] => fourth [page_4] => third )
下面给出了JSON格式
{s:6:"page_1";s:5:"third";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"fifth";}
任何人都可以帮助我
答案 0 :(得分:3)
您想序列化数组。
您需要使用serialize()
<?php
$a = array (
'page_1' => 'fifth',
'page_2' => 'first',
'page_3' => 'fourth',
'page_4' => 'third');
echo serialize($a);
// Outputs: a:4:{s:6:"page_1";s:5:"fifth";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"third";}
?>
答案 1 :(得分:0)
$ json = json_encode($ array);
,否则
$ array = json_decode($ json,true);
答案 2 :(得分:0)
当我在表格中插入值时,它会像
一样插入s:107:"a:4:{s:6:"page_1";s:5:"third";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"fifth";}";
不知道为什么当我显示它是正确的但是在表格中它插入如上所述