<form method="POST" action="cart.php">
<input type="text" name="product_name" placeholder="ชื่อสินค้า"><br>
<input type="number" name="quantity" placeholder="จำนวนสินค้า"><br>
<input type="submit" value="เพิ่มสินค้า">
</form>
session_start();
if(!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
if(isset($_POST['product_name']) && isset($_POST['quantity'])) {
$product_name = $_POST['product_name'];
$quantity = $_POST['quantity'];
$product = array('name' => $product_name, 'quantity' => $quantity);
array_push($_SESSION['cart'], $product);
}
session_start();
if(isset($_SESSION['cart'])) {
foreach($_SESSION['cart'] as $product) {
echo $product['name'] . ' (' . $product['quantity'] . ')<br>';
}
} else {
echo 'ไม่มีสินค้าในตะกร้า';
}
Scanner scanner = new Scanner(System.in);
System.out.print("ป้อนวันเกิดของคุณ (dd/mm/yyyy): ");
String dateOfBirthString = scanner.next();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date dateOfBirth = sdf.parse(dateOfBirthString);
Calendar cal = Calendar.getInstance();
cal.setTime(dateOfBirth);
int yearOfBirth = cal.get(Calendar.YEAR);
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
int age = currentYear - yearOfBirth;
System.out.println("อายุของคุณคือ: " + age + " ปี");
System.out.println("อายุของคุณคือ: " + age + " ปี");
var name: String = "John"
var age: Int = 25
var height: Double = 1.75
var name: String = "John"
name = "Jane"
var name: String = "John"
var age: Int = 25
var height: Double = 1.75
var isStudent: Boolean = true
fun main(args: Array<String>) {
var name: String = "John"
var age: Int = 25
var height: Double = 1.75
println("My name is " + name)
println("I am " + age + " years old")
println("My height is " + height)
}