note 128632 added to control-structures.foreach

From: Date: Sun, 25 Jun 2023 21:45:52 +0000
Subject: note 128632 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-220592@lists.php.net to get a copy of this message
$würfel = array(); if(isset($_REQUEST["submit"])){ for ($i = 0; $i < 5; $i++) { $würfelzahl = rand(1,6); array_push($würfel, $würfelzahl); } echo(implode(" ", $würfel). "<br>"); $stmt = $conn->prepare("INSERT INTO würfe(w1, w2, w3, w4, w5) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("iiiii", ...$würfel); $stmt->execute(); $zahlen = array_count_values($würfel); foreach ($zahlen as $zahl => $anzahl) { $result = $conn->query("SELECT COUNT(*) AS count FROM würfe WHERE w1 = $zahl OR w2 = $zahl OR w3 = $zahl OR w4 = $zahl OR w5 = $zahl"); $row = $result->fetch_assoc(); $gewürfelteZahl = $row['count']; echo "Die Zahl $zahl wurde bereits $gewürfelteZahl Mal gewürfelt.<br>"; } } So habe ich die Funktion genutzt, um eine Datenbank abfrage zumachen ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 217.252.56.19) ---- Manual Page -- https://php.net/manual/en/control-structures.foreach.php Edit -- https://main.php.net/note/edit/128632 Del: integrated -- https://main.php.net/note/delete/128632/integrated Del: useless -- https://main.php.net/note/delete/128632/useless Del: bad code -- https://main.php.net/note/delete/128632/bad+code Del: spam -- https://main.php.net/note/delete/128632/spam Del: non-english -- https://main.php.net/note/delete/128632/non-english Del: in docs -- https://main.php.net/note/delete/128632/in+docs Del: other reasons-- https://main.php.net/note/delete/128632 Reject -- https://main.php.net/note/reject/128632 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220592) next »