<?php

$csv = fopen('session.csv', 'r+');

$aCsv = [];
while ($f = fgetcsv($csv, null, ';')) {
    $aCsv[] = $f;
}
fclose($csv);

$_POST['description'] = str_replace( PHP_EOL, '<br />', $_POST['description'] );

$bFound = false;
foreach ($aCsv as & $row) {
    if ($row[0] == $_POST['name'] and $row[2] == $_POST['floor']) {
        $row[1] = $_POST['room'];
        $row[3] = ($_POST['description']);
        $bFound = true;
        break;
    }
}

if (!$bFound) {
    $aCsv[] = [$_POST['name'], $_POST['room'], $_POST['floor'], ($_POST['description']), 0];
}

$sCsv = '';
foreach ($aCsv as $row1) {
    $sCsv .= implode(';', $row1) . PHP_EOL;
}
file_put_contents('session.csv', $sCsv);

