I try to get parameters and run php script from terminal. If one of the parameters is not exists, I want to thrown an exception. I used getopt function. But I could not figure out how to thrown exception. And when I call the script
php myscript.php --file: file1.csv --unique-combinations: file2.csv
it's not working.
<?php
$files = getopt("file:unique-combinations:");
if(!files["file"]) {
echo "Please provide a CSV file with parameter file";
} else if(!files["unique-combinations"]) {
echo "Please provide a file name to save unique combinations with parameter unique-combinations";
} else {
$datas = array_count_values(file(files["file"]));
$fp = fopen(files["unique-combinations"], 'w');
foreach($datas as $data => $value) {
fputcsv($fp, $data);
}
fclose($fp);
}
?>
Could someone help me to figure out this.
$symbol all around.