Jump to content

Inlcuding variable.


Mutley

Recommended Posts

[quote author=Mutley link=topic=115687.msg471101#msg471101 date=1164064613]
So can I do this, if I wanted to include several?

<?PHP
$id = '1';
include('folder/file.php');
$id = '2';
include('folder/file.php');
$id = '3';
include('folder/file.php');
?>
[/quote]

If you need to include a "page" several times using a different variable I would think it would be more efficient to create a function for whatever the included page is doing. But, yes, you could do that IF you don't have any elements that can't be repeated in a single call - for instance you can't declare a function twice.
Link to comment
https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127652
Share on other sites

well then i would do something like this:

<?php

switch($_GET['id'])
{
    case "1":
    require_once "folder/file.php";
    break;

    case "2":
    require_once "folder/file.php";
    break;

    case "3":
    require_once "folder/file.php";
    break;
}

?>
Link to comment
https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127653
Share on other sites

[quote author=Destramic link=topic=115687.msg471112#msg471112 date=1164065486]
well then i would do something like this:

<?php

switch($_GET['id'])
{
    case "1":
    require_once "folder/file.php";
    break;

    case "2":
    require_once "folder/file.php";
    break;

    case "3":
    require_once "folder/file.php";
    break;
}

?>

[/quote]

Doesn't show anything doing that, no errors. This is for the same file, just different URL extensions.
Link to comment
https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127886
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.