没有changnig变量的PHP关联数组推送

时间:2015-11-20 13:51:02

标签: php arrays

当我尝试将我的数组var推送到另一个时,我得到了结果,但是当我再次尝试推新的时,旧的更改为新的,我该如何解决这个问题?

<?php 
//basisprijs en titel  die erbij komen, Dit moet aangepast worden. 
$nTemplate = $_POST['nTemplate'];
$tPrijs = $_POST['tPrijs'];

$tArray = array('titel' => $nTemplate, 'prijs' => $tPrijs);
/*echo $tArray['titel'];
echo $tArray['prijs'];*/

$basisPrijs=
array(
    array('titel' => 'template1', 'prijs' => '100'),
    array('titel' => 'template2', 'prijs' => '200'),
    array('titel' => 'template3', 'prijs' => '300'),
    array('titel' => 'template4', 'prijs' => '400')
);
array_push($basisPrijs, $tArray);
var_dump($basisPrijs);





$nOnderdeel = $_POST['nOnderdeel'];
$oPrijs = $_POST['oPrijs'];
$oArray = array('titel' => $nOnderdeel, 'prijs' => $oPrijs);

//onderdelen en titel die erbij komen, Dit moet aangepast worden.
$onderdelen=
array(
    array('titel' => 'Table', 'prijs' => '100'),
    array('titel' => 'Checkbox', 'prijs' => '200'),
    array('titel' => 'List', 'prijs' => '300'),
    array('titel' => 'Selectbox', 'prijs' => '400')
);
array_push($onderdelen, $oArray);
var_dump($onderdelen);

这是我从中获取值/信息

的表单
<form action="" method="post">
                        <div class="col-xs-3">
                            <input name="nTemplate" id="nTemplate" class="form-control" type="text" placeholder="Nieuw template">
                        </div>    
                        <div class="col-xs-2">
                            <input name="tPrijs" id="tPrijs" class="form-control" type="text" placeholder="Prijs">
                        </div> 
                        <div class="col-xs-3">
                            <input name="nOnderdeel" id="nOnderdeel" class="form-control" type="text" placeholder="Nieuw Onderdeel">
                        </div>    
                        <div class="col-xs-2">
                            <input name="oPrijs" id="oPrijs" class="form-control" type="text" placeholder="Prijs">
                        </div>
                        <div class="col-xs-2">
                            <button type="submit" class="btn btn-default">Toevoegen</button>
                        </div>
                    </form>

在我创建数组之后,在我推送之后,我将数组的这些值放在这样的选择和复选框中。

<form action="" method="post">
                 <div class="col-xs-12"> 
                     <label><?php echo $template.$verplicht; ?></label>
                 </div>
                     <div class="col-xs-4">
                         <select id="templates" 
                                class="form-control"  
                                name="templates">
                            <?php foreach($basisPrijs as $key => $value): ?>
                            <option value="<?php echo $basisPrijs[$key]["prijs"]; ?>">
                                <?php echo $basisPrijs[$key]["titel"]; ?>
                            </option>
                            <?php endforeach; ?>                          
                        </select>    
                    </div>
                    <div class="col-xs-12"><h4>Kies u onderdelen:</h4></div>
                <div class="checkbox col-xs-12">
                    <div class="row">
                        <div class="col-xs-12">
                 <?php foreach($onderdelen as $key => $value)
                    {echo "<div class='checkbox'>
                           <label><input class='check' type='checkbox' value='".$onderdelen[$key]["prijs"]."' 
                           name='".$onderdelen[$key]["titel"]."'>"
                           .$onderdelen[$key]["titel"]."</label></div>"
                    ;}?>
                        </div>
                        <!--<div class="col-xs-4">
                         <?php /*foreach($onderdelen as $key => $value)
                            {
                                echo "<p id='".$key."'>Prijs:".$onderdelen[$key]["prijs"]."</p>";
                            }*/?>
                        </div>-->
                    </div>
                </div>
                </form>

实际上我想要创建的是一个输入,我可以创建新的复选框和新的选择,如果输入是empthy,那么它将不会被推送到数组。

0 个答案:

没有答案