チェック配列
$allow = array(
"pdf"=>"application/pdf",
"doc"=>"application/msword",
"docx"=>"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"docx"=>"application/zip" // this will be overridden by above index.
);
if(in_array("application/vnd.openxmlformats-officedocument.wordprocessingml.document",$allow)){
echo "true";
}else{
echo "false";
}
あなたの配列は、DOCX、その最後の一つは古いもので上書きされます、同じキーを持ちます。
あなたの場合
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
overriden by "application/zip"
EDIT
$allow = [
"pdf"=>"application/pdf",
"doc"=>"application/msword",
"docx"=>[
"docx"=>"application/zip",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"]
];
AND条件になります。
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
echo in_array_r("application/vnd.openxmlformats-officedocument.wordprocessingml.document", $allow) ? 'true' : 'false';
私はlinkを参考にしました。
2つの配列要素に同じキーを使用した場合、同じキーで2つの配列要素を定義することはできません。 –
の2つのdocxファイルがあります。 –
@AbuAyyub:docx1、docx2 ?? –