PHP code examples
5 short, tested snippets. Pick one to see the code with notes, or search Zest for something specific, such as “php query with pdo”.
- Query with PDO$pdo = new PDO("mysql:host=localhost;dbname=app;charset=utf8mb4", $user, $pass,
- Read a file$text = file_get_contents("data.txt");
- JSON encode and decode$json = json_encode(["a" => 1, "b" => [1, 2]], JSON_PRETTY_PRINT);
- array_map, array_filter$nums = [1, 2, 3, 4];
- Hello world<?php