Jump to content

Archived

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

zasnemo

PLEASE help!!!

Recommended Posts

how can i pass variables from an function to a include inside it?

<?php
// index.php
function a() {
    $a= 'apples';
    include('fuit.php');

}

?>

<?php
// fruit.php
    echo $a;
?>

THANKS!!

Share this post


Link to post
Share on other sites
you don't need to pass it anything... $a will be global in fruit.php so you can do it just as you are doing it in your code

Share this post


Link to post
Share on other sites
If that is an exact copy, you misspelled fruit.  That might be the error, cause otherwise that should work.

Share this post


Link to post
Share on other sites
oh shite, i must of done the example wrong then.

im trying to edit SMF, which contains a:

function template_main_above()
{
global $context;
print_r($context);

$context comes out fine.

and in that function i include:

include('a.php');

in that a.php I try to
print_r($context);

but it doesnt come out :-S

Share this post


Link to post
Share on other sites
I doubled checked and added:

$fruit = 'aaaaaaa';

in

function template_main_above() function


then in my include('a.php');

I echo $fruit; but no answer :-S

Share this post


Link to post
Share on other sites
<?php
$include="a.php";

function template_main_above($include)
{
global $context;
print_r($context);

$context comes out fine.
echo $include;
}

?>



Share this post


Link to post
Share on other sites
mmm, wheres the include? I dont want to echo...

<?php
function template_main_above()
{
global $context;
print_r($context); // $context comes out fine.

include('aaaa.php');
}

?>

<?php //aaaa.php

global $context;
print_r($context); // $context DOESNT come out fine.

?>

Share this post


Link to post
Share on other sites
but guys... to make it simpler, this doesnt even work:

[code]
<?php
function template_main_above()
{
$aaa = 'aaa';
echo $aaa; // comes out fine
include('aaaa.php');
}

?>

<?php //aaaa.php

echo $aaa; // doesnt come out fine

?>
[/code]

:'( :'(

Share this post


Link to post
Share on other sites

×

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.