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); Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted October 7, 2014 Solution Share Posted October 7, 2014 (edited) Pass $lang as an additional argument in the function call function testFunction($id, $settings, $db, $lang){ Edited October 7, 2014 by Barand Quote Link to comment 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!! 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.