如何在单个变量中追加不同的Array值

时间:2015-02-18 06:17:48

标签: php

<tr>
    <td><p style="color:#999; font-size:14px; text-align:right;">Please select your Board :</p></td>
    <td>
    <input type="checkbox" name="board[]" id="all" value="cbse">CBSE
    <input type="checkbox" name="board[]" id="sci" value="cse/Ise">ICSE/ISE
    <input type="checkbox" name="board[]" id="mat" value="State">State
    <input type="checkbox" name="board[]" id="mat" value="International">International
    </td>
    </tr>

    <tr>
    <td><p style="color:#999; font-size:14px; text-align:right;">Please select Subject :</p></td>       
    <td>      
    <input type="checkbox" name="classfivesubject[]" id="all" value="allsubject">All Subject
    <input type="checkbox" name="classfivesubject[]" id="sci" value="science">Science
    <input type="checkbox" name="classfivesubject[]" id="mat" value="maths">Maths
    </td>
    </tr><!--end of select subject row-->

以下是我的PHP值:

$segment=$_SESSION["segment"];
$board=$_POST['board'];
$subject5=$_POST['classfivesubject'];
$segment=implode(",",$segment);
$board=implode(",",$board);
$class5data=implode(",",$subject5);

同样适用于class8:

$eightboard=$_POST['eightboard'];
$subject8=$_POST['classeightsubject'];
$board=implode(",",$eightboard);
$class8data=implode(",",$subject8);

我希望将这样的值存储在我的数据库中的一列:classconducted。

segment:class I_V
Board:CBSE,STATE
Subject:AllSubject,Maths,Science

segment:class V-VIII
Board:CBSE, STATE
SUbject:AllSubject,Maths,Science

我的问题是如何将所有值附加到单个变量中。假设变量名是classconducted。因此,基于导师选择课程,我将所有数据整合到一个变量中并将其放入一个列中。我希望你理解我的问题,因为每个导师都在进行不同的标准和不同的主题和不同的媒介。如何将所有值都放在单个变量中?

我想要这样的输出:classconducted。

    segment:class I_V
    Board:CBSE,STATE
    Subject:AllSubject,Maths,Science

    segment:class V-VIII
    Board:CBSE, STATE
    SUbject:AllSubject,Maths,Science

1 个答案:

答案 0 :(得分:0)

您可以将json编码数据存储到单个列中,如

$classconducted = json_encode(array('segment'=>'your segment value','Board'=>'board value','Subject'=>'subject value'));