Created
November 12, 2023 14:16
-
-
Save katsube/4d83679880e1a7fe590eafd259710b19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 重複を削除する | |
* | |
*/ | |
//------------------------------------ | |
// グローバル変数 | |
//------------------------------------ | |
// 好きなゲーム一覧 | |
$favogames = [ | |
'ポケモン', | |
'ドラゴンクエスト', | |
'メタルギアソリッド', | |
'ポケモン', | |
'ファイナルファンタジー', | |
'メタルギアソリッド', | |
'バイオハザード', | |
'バイオハザード', | |
'メタルギアソリッド' | |
]; | |
//------------------------------------ | |
// 重複を削除 | |
//------------------------------------ | |
$list = removeDuplicate($favogames); | |
// 結果を表示 | |
for($i=0; $i<count($list); $i++){ | |
printf("%s\n", $list[$i]); | |
} | |
/** | |
* 重複を削除する | |
* | |
* @param [array] $array | |
* @return array | |
*/ | |
function removeDuplicate($array) { | |
$uniq = [ ]; // 連想配列として利用する | |
// ★ここを回答してください★ | |
// この行と、この上の1行は削除してください。 | |
return array_keys($uniq); // ['ポケモン', 'ドラゴンクエスト', ...] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment