PHP 8.5.0 Released!

Voting

: two minus zero?
(Example: nine)

The Note You're Voting On

Sbastien
2 years ago
I use array_diff() and array_intersect() to check the completness of a CSV file before processing :

<?php

$header = fgetcsv($stream, ...$csv_options); // ['id', 'name', 'sex']

$awaited = ['id', 'name', 'email']; // Header cols I need in the CSV

$present = array_intersect($header, $awaited); // ['id', 'name']

if (count($present) < count($awaited)) { // 2 < 3 => true, problem!
    $missing = array_diff($present, $awaited); // ['email']
    $missing = join(', ', $missing);
    echo "Missing cols: {$missing}\r\n";
}

<< Back to user notes page

To Top