PHP strpos无法正常工作(路径生成器)

时间:2016-06-22 04:44:13

标签: php strpos

我想创建一个从数组生成图像路径的函数。该函数有一个参数,该参数供您决定从哪个文件夹中选择图像。 所以我在一个数组中有90个元素,每个元素都是一个路径。现在我不想要一个.png图像,所以我想创建这样的东西(但它对我不起作用):

public function getRandomPath($RoboticOrArenag)
{
    if ($RoboticOrArenag == 'Robotic' || $RoboticOrArenag == 'robotic') {
        $countofarray = count($this->allImagesRobotic);
    } else if ($RoboticOrArenag == 'Arenag' || $RoboticOrArenag == 'arenag') {
        $countofarray = count($this->allImagesArenag);
    } else {
        $RoboticOrArenag = 0;
    }
        $randomNumber = rand(0, $countofarray);
    if ($RoboticOrArenag == 'Robotic' || $RoboticOrArenag == 'robotic') {
        if($randomNumber==50){
            $randomNumber--;
        }
        else if ($randomNumber==0){
            $randomNumber++;
        }
        $randomNumberPath = $this->allImagesRobotic[$randomNumber];
    } else if ($RoboticOrArenag == 'Arenag' || $RoboticOrArenag == 'arenag') {
        if($randomNumber==33){
            $randomNumber--;
        }
        else if ($randomNumber==0){
            $randomNumber++;
        }
        $randomNumberPath = $this->allImagesArenag[$randomNumber];
        while(strpos($randomNumberPath, '.png') == true){
            $randomNumber = rand(0, $countofarray);
            $randomNumberPath = $this->allImagesArenag[$randomNumber];
        }
    } else {
        $randomNumberPath = 0;
    }
    $randomPath = "/img/$RoboticOrArenag/$randomNumberPath";
    return $randomPath;
} 

0 个答案:

没有答案