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!! Link to comment https://forums.phpfreaks.com/topic/18859-please-help/ 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 ? Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81424 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 Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81426 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. Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81428 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 Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81429 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 Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81433 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;}?> Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81437 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.?> Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81441 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] :'( :'( Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81442 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 Link to comment https://forums.phpfreaks.com/topic/18859-please-help/#findComment-81464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.