I tried to include the php file in array like that but it is not working
username.php file is : "mohammed", "ahmed", "hafian", "gimmy", "osama"
and the main file is : $usernames = array(include 'usernames.php');
I tried to include the php file in array like that but it is not working
username.php file is : "mohammed", "ahmed", "hafian", "gimmy", "osama"
and the main file is : $usernames = array(include 'usernames.php');
In usernames.php do:
<?php
return ["mohammed", "ahmed", "hafian", "gimmy", "osama"];
In foo.php do:
$usernames = include 'usernames.php';
RTM: https://www.php.net/manual/en/function.include.php#example-145
You will need to open and read the file, you can't just include and expect it to parse the file and store into your array. Also, can you make usernames.php a text file and not PHP code? You don't want to be parsing PHP code. I think you'll need to approach it like this:
`<?php
$fn = fopen("usernames.txt","r");
while(! feof($fn)) {
$result = fgets($fn);
# parse line and append to array
}
fclose($fn);
?>`