$products = array( array('id' => 123, 'name' => 'Product A', 'price' => 10.99), array('id' => 456, 'name' => 'Product B', 'price' => 15.99), array('id' => 789, 'name' => 'Product C', 'price' => 20.99) ); $product = array_filter($products, function($item) { return $item['id'] == 123; }); $result = array_values($product); echo $result[0]['name']; // Output: Product A
$pdo = new PDO("mysql:host=localhost;dbname=mydb", "username", "password"); $stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id"); $stmt->execute(array(":id" => 1)); $user = $stmt->fetch(PDO::FETCH_ASSOC); echo $user['name']; // Output: John DoePackage library: PHP Data Object (PDO) is used in this example.