jacob21 Posted October 7, 2014 Share Posted October 7, 2014 I have included language file and function file in my index.php include 'includes/functions.php'; include 'languages/english.php'; english.php contains <?php $lang['success']['a'] = 'Settings have been updated.'; $lang['error']['b'] = 'Database error. Please try again later!'; ................................. ?> functions.php <?php function testFunction($id, $settings, $db){ $query = 'UPDATE table_name SET a = a + :a WHERE id = :id'; $update = $db->prepare($query); $update->bindParam(':a', $settings['a'], PDO::PARAM_INT); $update->bindParam(':id', $id, PDO::PARAM_INT); $success = $update->execute(); if($success){ print $lang['success']['a']; }else{ print $lang['error']['b']; } } ................................................. ?> Now if i print testFunction(); i got Undefined variable: lang in ............. If i include 'languages/english.php'; in testFunction() then everything works. Any other way to make $lang working without including language file in testFunction(). (Sorry for my bad english) print testfunction(2, $settings, $db); Link to comment https://forums.phpfreaks.com/topic/291488-lang-inside-function/ Share on other sites More sharing options...
Barand Posted October 7, 2014 Share Posted October 7, 2014 Pass $lang as an additional argument in the function call function testFunction($id, $settings, $db, $lang){ Link to comment https://forums.phpfreaks.com/topic/291488-lang-inside-function/#findComment-1492952 Share on other sites More sharing options...
jacob21 Posted October 7, 2014 Author Share Posted October 7, 2014 Pass $lang as an additional argument in the function call function testFunction($id, $settings, $db, $lang){ Thanks!! Link to comment https://forums.phpfreaks.com/topic/291488-lang-inside-function/#findComment-1492953 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.