Skip to content

Instantly share code, notes, and snippets.

@hijarian
Created March 8, 2013 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hijarian/5119723 to your computer and use it in GitHub Desktop.
Save hijarian/5119723 to your computer and use it in GitHub Desktop.
В исходном массиве (размер 30 элементов), заполненный цифрами случайным образом, замените все повторные вхождения цифр на 0, а все оставшиеся элементы массива поместить в отдельный массив. Для контроля результата сделайте распечатку массивов, в том числе исходного.
$null_value = 0;
$input = array();
for ($i = 0; $i < 25; ++$i) {
$input[] = mt_rand(1, 10);
}
print_r($input);
$values_to_null = array_diff_key($input, array_unique($input));
foreach ($values_to_null as $key => $value) {
$input[$key] = $null_value;
}
print_r($input);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment