/ Gists / array.php
On gists

array.php

array.php Raw #

<?php



$states = ['Přijatá', 'Nová', 'K zaplacení', 'Zaplaceno', 'Expedováno', 'Doručeno'];
$currentState = isset($_GET['state']) ? $_GET['state'] : 'K zaplacení';

$totalStates = count($states);
$currentIndex = array_search($currentState, $states);
$prev = null;
$next = null;
$prevAll = [];
$nextAll = [];

foreach ($states as $index => $state) {

    if ($index < $currentIndex) {
        $prev = $state;
        $prevAll[] = $state;
    }

    if ($index > $currentIndex && $next === null) {
        $next = $state;
    }

    if ($index > $currentIndex) {
        $nextAll[] = $state;
    }

}


$meta = [
    'prev' => $prev, // predchozi stav vuci aktualnimu ...
    'prevAll' => $prevAll, // vsechny predchozi vuci aktualnimu  ...
    'next' => $next, // nasledujici stav vuci aktualnimu
    'nextAll' => $nextAll, // vsechny nasledujici po aktualnim
    'currentStateNumber' => $currentIndex, // aktualni cislo stavu, K zaplaceni => 2, Doručeno => 6 atd.
    'totalStates' => $totalStates, // celkovy pocet stavu, tj. 6
];




echo '<pre>';
print_r($meta);