I have created three files and in one of them i would like to make a loop over a Section to output the name and the price from my array
<?php
session_start();
?>
<?php
$a=array(
array('id'=>'1','name'=>'Milch','price'=>'12'),
array('id'=>'2','name'=>'Reis','price'=>'13'),
array('id'=>'3','name'=> 'Öl', 'price'=>'14'),
array('id'=>'4','name'=>'Salz','price'=>'15'),
array('id'=>'5','name'=>'Zucker','price'=>'16'),
);
if(empty($_SESSION['warenkorb'])){
echo 'Warenkorb leer';
}
else {
foreach($_SESSION['warenkorb'] as $key=>$value){
$_SESSION['warenkorb']=array();
print_r($value['name'].': '.'$'.$value['price'].PHP_EOL.'<br />');
}
}
?>
And this is another file with a lesson that i output from it only the id
<?php
session_start();
?>
?php
include 'produkte.php';
if(!isset($_SESSION['warenkorb'])){
$_SESSION['warenkorb']=array();
}
if(isset($_POST['id'])){
foreach($a as $key =>$value){
if($value['id']==$_POST['id']){
$_SESSION['warenkorb'][]= $_POST['id'];
}
}
}
print_r(count($_SESSION['warenkorb']));
?>