如何以给定格式在会话数组中存储数据?

时间:2015-04-22 15:58:21

标签: php session

Category Name
  List A = Rm 20
  List B = Rm 50

Category Name
  List A = Rm 40

category Name
  List A = Rm 80
  List B = Rm 40
  List C = Rm 25

我试过

$_SESSION['info']=array('category'=>$category,'list'=>$list,'rate'=>$rate);

但它并不像所需格式那样显示。任何人都可以帮忙吗?`

编辑:

我认为我没有明确说明。

项目类别,列表和费率的值来自用户输入。

所以我把它们存储在这样的变量中:

PHP

$category[]=$_POST['category'];<br/>
$list[]=$_POST['list'];
$rate[]=$_POST['rate'];

像这样存储在会话数组中:

$_SESSION['info']]=array('level'=>$level,'subject'=>$subject2,'rate'=>$rate2);`

HTML

<input type="checkbox" name="category['category name']" id="category" class=category" value="1">

<input type="checkbox" name="list['category name']" id="list" value="'List id'">

<input type="textbox" name="rate['List name']" class="rate" value="" id="'List Name'">

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

$_SESSION['info'] = Array(
    'Category Name' => Array(
        'List A' => 'Rm 20', // don't forget "," if you're adding additional item.
        'List B' => 'Rm 50'
    ), 
    'Category Name' => Array(
        'List A' => 'Rm 40'
    )
    // Etc..
);