Code · 1 file

Sample PHP File

PHP is a web scripting language behind WordPress and Laravel. These files are served as plain text and never executed. The PHP sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

PHP · 749 B

Sample PHP file

An idiomatic PHP example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.php — first linesPHP
<?php
// Sample PHP 8 script — samplefiles.com
declare(strict_types=1);

final class Customer
{
    public function __construct(
        public readonly int $id,
        public readonly string $name,
        public readonly float $balance,
    ) {}

    public function isVip(): bool
    {
        return $this->balance >= 10_000;
    }
}

function totalBalance(array $customers): float
{
    return array_sum(array_map(fn (Customer $c) => $c->balance, $customers));
}

$customers = [new Customer(1, 'Ada', 12_500), new Customer(2, 'Grace', 830.5), new Customer(3, 'Linus', 10_000)];
foreach ($customers as $c) {

File details

Size
749 B (749 bytes)
MIME type
text/x-php
SHA-256
6d0fb79004d34dc2e32db282e4c524edfcefce9119a8bfcfbd866156c902cf69
MD5
d8bdf0dabc3e13de9896f6414fe98d09

Download from the command line

curl -L -o sample.php https://files.samplefiles.com/code/php/sample.php

Or check the download in your browser with the checksum calculator.