开发者

PHP table field values into an array or multi-dimensional array

I haven't actually came across this situation yet but i will probably have a need for it in the near future. In current frameworks or CMS like joomla I have noticed multiple parameters and values stored in 1 field within a database table. what wo开发者_开发技巧uld be the best way to extract these values as a key => value in an array? so say a field / column has (Joomla example):

show_title=1
link_titles=1
show_intro=blah blah blah
show_section=
link_section=

and so on ......

how would such break these up in a nice clean way? it also seems the entries have a new line to break apart each parameter. Is it actually possible to explode a /n?


You can store values in json ecoded form. In PHP you can use something like this:

PHP json_encode

Quoting Example from above page

<?php
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);    
$val= json_encode($arr);

//Insert $val in column
?>

To fetch the values use PHP json_decode


Joomla has built in methods from retrieving this kind of parameters. Pay a visit to Joomla! Component Parameters

Also, use documentation of JParameter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜