Jump to content

$lang inside function


jacob21

Recommended Posts

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

Archived

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

×
×
  • Create New...

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.