Explorar o código

finish script

dbm %!s(int64=4) %!d(string=hai) anos
pai
achega
1f9d4c802a
Modificáronse 1 ficheiros con 39 adicións e 0 borrados
  1. 39 0
      get-unique-items.php

+ 39 - 0
get-unique-items.php

@@ -4,3 +4,42 @@
 //	April 12, 2021
 
 
+if (isset($argv[1])){
+	
+	if (file_exists($argv[1])){
+		
+		$input_file = fopen($argv[1], "r") or die("Unable to open file.");
+		$input = fread($input_file, filesize($argv[1]));
+		fclose($input_file);
+		
+		
+		$values = explode(',', $input);
+		$unique = array();
+		
+		foreach ($values as $value){
+		
+			if (!in_array((string)$value, $unique)){
+				array_push($unique, (string)$value);
+			}
+		}
+		
+		echo "\n Results\n =========================\n";
+		foreach ($unique as $u){
+			echo " " . $u . "\n";
+		}
+	}
+	
+	else{
+		
+		echo " > Sorry, file '" . $argv[1] . "' does not exist.\n";
+		return 1;
+	}
+}
+else{
+
+	echo "\n Incorrect Syntax\n =========================\n";
+	echo " > Missing filename with values.\n";
+	echo "\n > Usage Example:\n";
+	echo "   > \"php " . $argv[0] . " values.txt\n";
+	return 1;
+}