Jump to content
php.lv forumi

array un include lapa


waplet

Recommended Posts

Atsaucoties uz bubu veido,

$a = array("news", "topics", "whatever");

kā, lai uztaisa, ka , ja piemēram, if(in_array($_GET['p'])){.. lai inklūdo piemēram, jebkādu , kādu grib norādītu php failu.. kā tas būtu jātaisa, tas divdimensionālais arrays :?

Link to comment
Share on other sites

šis inklūdos "jebkādu" lapu, bet tikai no arraya ;)

$a = array("news", "topics", "whatever");
if (in_array($_GET['p'], $a)) include $_GET['p'] . '.php';
else include 'defaultais.php';

ohh, un to visu, protams, var vienā rindiņā ar ternary operatoru:

include (in_array($_GET['p'], array("news", "topics", "whatever")) ? $_GET['p'] : 'defaultais') . '.php';

Edited by 2easy
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...