fork(1) download
  1. <?php
  2.  
  3. $filenames = array(
  4. 'Vacation (10).png',
  5. 'Vacation (Me and Mom) (21).png',
  6. 'Vacation (5) (1).png',
  7. );
  8.  
  9. $files = array();
  10.  
  11. foreach ( $filenames as $filename ) {
  12. if ( preg_match( '/^.*\((\d+)\)/s', $filename, $matches ) ) {
  13. $files = array_merge($filename, $matches[1]);
  14. echo "$filename => $matches[1]\n";
  15. } else {
  16. echo "$filename => no match!\n";
  17. }
  18. }
  19.  
  20. $value = max($files);
  21. $key = array_search($value, $files);
  22.  
  23. foreach ($files as $result) {
  24. echo $result->type;
  25. echo "<br>";
  26. }
  27.  
  28.  
Success #stdin #stdout #stderr 0.02s 25828KB
stdin
Standard input is empty
stdout
Vacation (10).png => 10
Vacation (Me and Mom) (21).png => 21
Vacation (5) (1).png => 1
stderr
PHP Warning:  array_merge(): Expected parameter 1 to be an array, string given in /home/wCwVsW/prog.php on line 13
PHP Warning:  array_merge(): Expected parameter 1 to be an array, string given in /home/wCwVsW/prog.php on line 13
PHP Warning:  array_merge(): Expected parameter 1 to be an array, string given in /home/wCwVsW/prog.php on line 13
PHP Warning:  max(): When only one parameter is given, it must be an array in /home/wCwVsW/prog.php on line 20
PHP Warning:  array_search() expects parameter 2 to be array, null given in /home/wCwVsW/prog.php on line 21
PHP Warning:  Invalid argument supplied for foreach() in /home/wCwVsW/prog.php on line 23