1

I have 2 files. first find.php

he has a script


<?php
require("config/connect_bd.php"); // create a connection to the database
$query = "SELECT * FROM `translate` WHERE 1"; //Looking for a translation by ID
$result = mysqli_query($con, $query);
$word = array();
foreach($result as $row){ // Loop through the result
$word[]= ['key'=>$row['id'],'ru'=>$row['ru'],'en'=>$row['en'],'kz'=> $row['kz']];
}



$site_lang = $_GET['lang'];
if(is_null($site_lang)){
$site_lang = 'ru';
}

function lang_base($lang,$id_base){
for($i=0;$i<count($word);$i++){
if($word[$i]['key'] == $id_base){
echo $word[$i][$lang];
break;
}
}

}


?>

The second script main.php calls the lang_base function

<?php
require_once("find.php"); // подключем перевод
lang_base('ru','123');
?>

But it doesn't see the variable (array) $word What to do?

Tried changing require to require_once and vice versa.

Put in lang_base global $word
Still can't see...
  • 1
    Does this answer your question? [Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?](https://stackoverflow.com/questions/16959576/reference-what-is-variable-scope-which-variables-are-accessible-from-where-and) – M. Eriksson Jan 19 '23 at 07:55
  • _Side note:_ When posting code, please make sure you use some sensible code indention. It's really hard to read, follow what statements belongs to what blocks etc when there's no code indention at all. The easier you make it for us to read the code, the more inclined we'll be to help. – M. Eriksson Jan 19 '23 at 07:57

0 Answers0