dongming0505 2015-03-02 08:11
浏览 84
已采纳

如何比较数组中的文件扩展名并抛出错误?

I've following array of file extensions titled $aSupportedImages:

Array
(
    [0] => jpeg
    [1] => jpg
    [2] => gif
    [3] => png
)

I've another array titled $values as follows :

Array
(
    [vshare] => Array
        (
            [course_error.png] => Array
                (
                    [0] => https://www.filepicker.io/api/file/Y0n99udSqS6ZJWYeYcUA
                )

            [before_login.png] => Array
                (
                    [0] => https://www.filepicker.io/api/file/19FWbHh1QNGCo2OINxI6
                )

            [Sample_1.docx] => Array
                (
                    [0] => https://www.filepicker.io/api/file/INjMeEhCSjpZSfZJmQUb
                )

        )

)

Now you can see that each key in an array [vshare] is a file name. I want to check the extension of each of such file with the extensions present in an array $aSupportedImages. If any of the files have different extension than those present in the array $aSupportedImage the loop should get break and it should return false.

In above case for third file it should return false. As .docx is not present in an array $aSupportedImages

How should I do this? Please help me.

  • 写回答

3条回答 默认 最新

  • dqc19941228 2015-03-02 08:28
    关注

    This should break if there's a file with unsupported extension

    foreach($values['vshare'] as $file)
    {
        if(!in_array(pathinfo($file, PATHINFO_EXTENSION), $aSupportedImages))
            break;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)