## Frage im Vorstellungsgespräch

Vorstellungsgespräch für eine Beschäftigung als Senior PHP Developer

-Berlin, Berlin

# Given an array of numbers [1,3,3,5,9,4,1,10,9,7,2,7], Write a php function that will print numbers that are not duplicated in array. [5,4,10,2]

Antwort

## Antworten zu Vorstellungsgespräch

4 Antworten

0

The simplest solution for me is to loop through array, unset the current value then check if it is in the array which mean its duplicate and we add it to duplicated values array, if not ,its unique and added to another array for unique numbers .. in every iteration we check the number in the main array and in the duplicated array .. finally we print the unique array.

Anonym am

0

\$firstarray = [1,3,3,5,9,4,1,10,9,7,2,7]; \$secondarray = []; foreach (\$firstarray as \$i) { if (array_key_exists(\$i, \$secondarray)) { \$secondarray[\$i] += 1; } else { \$secondarray[\$i] = 1; } } \$result = []; foreach (\$secondarray as \$i=>\$j) { if (\$j==1) { array_push(\$result, \$i); } } echo var_dump(\$firstarray); echo "<br>"; echo var_dump(\$result);

Anonym am

0

\$firstarray = [1,3,3,5,9,4,1,10,9,7,2,7]; \$secondarray = []; foreach (array_count_values(\$firstarray) as \$i=>\$j) { if (\$j==1) { array_push(\$secondarray, \$i); } } echo var_dump(array_count_values(\$firstarray)); echo "<br>"; echo var_dump(\$secondarray);

another way am

0

Anonym am

Mind. ein Kommentar wurde entfernt.
Weitere Informationen finden Sie in unserem Verhaltenskodex und in unseren Nutzungsbedingungen.

## Antwort oder Kommentar posten

Um dies zu kommentieren, bitte anmelden oder Konto anlegen.