zasnemo Posted August 28, 2006 Share Posted August 28, 2006 how can i pass variables from an function to a include inside it?<?php// index.phpfunction a() { $a= 'apples'; include('fuit.php');}?><?php// fruit.php echo $a;?>THANKS!! Quote Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 28, 2006 Share Posted August 28, 2006 works perfect here...what about a(); at the end of your index.php ? Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted August 28, 2006 Share Posted August 28, 2006 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 Quote Link to comment Share on other sites More sharing options...
ChaosXero Posted August 28, 2006 Share Posted August 28, 2006 If that is an exact copy, you misspelled fruit. That might be the error, cause otherwise that should work. Quote Link to comment Share on other sites More sharing options...
zasnemo Posted August 28, 2006 Author Share Posted August 28, 2006 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 toprint_r($context);but it doesnt come out :-S Quote Link to comment Share on other sites More sharing options...
zasnemo Posted August 28, 2006 Author Share Posted August 28, 2006 I doubled checked and added:$fruit = 'aaaaaaa';infunction template_main_above() functionthen in my include('a.php');I echo $fruit; but no answer :-S Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 28, 2006 Share Posted August 28, 2006 <?php$include="a.php";function template_main_above($include){global $context;print_r($context);$context comes out fine.echo $include;}?> Quote Link to comment Share on other sites More sharing options...
zasnemo Posted August 28, 2006 Author Share Posted August 28, 2006 mmm, wheres the include? I dont want to echo...<?phpfunction template_main_above(){global $context;print_r($context); // $context comes out fine.include('aaaa.php');}?><?php //aaaa.phpglobal $context;print_r($context); // $context DOESNT come out fine.?> Quote Link to comment Share on other sites More sharing options...
zasnemo Posted August 28, 2006 Author Share Posted August 28, 2006 but guys... to make it simpler, this doesnt even work:[code]<?phpfunction template_main_above(){$aaa = 'aaa';echo $aaa; // comes out fineinclude('aaaa.php');}?><?php //aaaa.phpecho $aaa; // doesnt come out fine?>[/code] :'( :'( Quote Link to comment Share on other sites More sharing options...
zasnemo Posted August 28, 2006 Author Share Posted August 28, 2006 Solved it, dont know how... whatever :P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.