I have one file dbConfig.php which contains simple array data.
<?php
return [
'host' => 'localhost',
'database_name' => 'mitesh_practice',
'database_user_name' => 'root',
'database_password' => 'Kadiya@123'
]
?>
I have another file which is Model.php
So in Model.php I have created one variable $dbConfig
;
So in $dbConfig
variable I want to store array of dbConfig.php
file
$filename = 'path/to/your/array_data.txt';
// Read the contents of the file
$serializedArray = file_get_contents($filename);
// Unserialize the contents to get the array back
$array = unserialize($serializedArray);
print_r($array);
I tried this but I failed because it reads .txt file
2
Answers
If your file returns a variable, you can retrieve it in a simple require: https://www.php.net/manual/en/function.require.php#Hcom126279
You Include your file using require_once and then assign using $dbConfig variable of Model.php
Code: