reklanummer - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of reklanummer.php

  1. <?php
  2. $Reklamationsnummer=array('L_2023434_334','2021_0124','2021_10000','2021_9999');
  3.  
  4.         $year = '2021';
  5.  
  6. foreach($Reklamationsnummer as $val){
  7.             if(ord($val) == 50){
  8.                 $reklanum[] = $val;
  9.             }
  10. }
  11.             if(empty($reklanum) === true){
  12.                 $counter = '0001';
  13.                 $neuReklanum = $year.'_'.$counter;
  14.                 echo('neue Rekla ist: '.$neuReklanum."\n");
  15.             }else{
  16.                 //In $maxReklanum wird die maximale Reklamationsnummer, die mit '2' beginnt gespeichert
  17.                 if(!empty($reklanum)) $maxReklanum = max($reklanum);
  18.                 //Anschließend wird aus der Nummer der Anhang ohne Jahr extrahiert und 
  19.                 $ergebnis = substr($maxReklanum, 5);
  20.                 $ergebnis++;
  21.                 $ergebnisTrimm = ltrim($ergebnis,'0');
  22.                 $length = 4;
  23.                 /*Überprüft das Jahr der Reklamationsnummer. Wenn das aktuelle Jahr gleich dem
  24.                 der Reklamationsnummer ist, wird eine neue Nummer durch Hochzählen erzeugt
  25.                 und in das Prozessfeld 'Reklamationsnummer' übergeben. Andernfalls wird wieder 
  26.                 neu von '0001' begonnen*/
  27.                 if($year == substr($maxReklanum,0,-5)){
  28.                     $ergebnisTrimm = str_pad($ergebnisTrimm ,$length,'0000', STR_PAD_LEFT);
  29.                     $maxReklanum = $year.'_'.$ergebnisTrimm;
  30.                     echo('Neue Nummer ist (Jahr gleich): '.$maxReklanum."\n");
  31.                 }else{
  32.                     $ergebnisTrimm = '0001';
  33.                     $maxReklanum = $year.'_'.$ergebnisTrimm;
  34.                     echo('Neue Nummer ist: '.$maxReklanum."\n");
  35.                 }
  36.             }
  37.               
  38.         
File Description
  • reklanummer
  • PHP Code
  • 21 Jun-2021
  • 1.7 Kb
You can Share it: