When i try to push my array var to another one i get the result, but when i try again to push a new one the old one change to the new one, how can i fix this?
<?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);
This is my form from where i get the values/info
<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>
After i create the Array and after i push it i put this values of the array in a select and checkbox like this.
<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>
Soo actually what i want to create is an input where i can create new checkbox and new select and if an input is empthy than it will not be push to the array.