$stock[$pos] + 1) && $max >= $fwd) { $stock[$fwd] = $stock[$pos] + 1; $queue[] = $fwd; } if (($stock[$back] == -1 || $stock[$back] > $stock[$pos] + 1) && $back > 1) { $stock[$back] = $stock[$pos] + 1; $queue[] = $back; } } echo $stock[$x[0][0]];