我可以多次使用IF在PHP中的多个选项之间切换吗?

Ali*_*der 1 php scripting if-statement

嘿,我的网上有9种类型.我必须为每种类型设置不同的关键字.用这个脚本;

if ($type = movie) {
$yazdir = "DVDRip, DVDScr";
}
elseif ($type = game) {
$yazdir = "Full Version, Patch";
}
Run Code Online (Sandbox Code Playgroud)

我可以写两种类型的关键字.如何正确地重复其他类型?(echo paramether必须是$ yazdir)

Yad*_*ada 5

三种选择:

  1. 添加更多elseif
  2. 您可以使用 switch

http://php.net/manual/en/control-structures.switch.php

3.使用关联数组

$types = array( 
         "movies" => "DVDRip, DVDScr",
         "games" => "Full Version, Patch",
         ...
       );
Run Code Online (Sandbox Code Playgroud)

  • *咳嗽*谷歌*咳嗽* (2认同)
  • 你刚刚复制粘贴其他2个答案吗?耶稣!http://stackoverflow.com/posts/2274630/revisions (2认同)