Use $variable from file1.php in file2.php (different file paths)

I have $variable_1 = '5'; in /public/includes/themes/theme-section-users-score.php and I want to use its value in another php file with a different location /plugins/name/other/users-time.php , I tried using include_once , require_once and others but I can't, might be the .htaccess doesn't allow me? please help, thanks in advance.

Topic include php plugins themes Wordpress

Category Web


Store the value is a function or make it global;

function get_variable_1(){

    return 5;

}

OR

global $variable_1;
$variable_1 = 5;

But.. really, what you need to do it to read a bit more about the basic of PHP to understand how variables and functions work - global variables are not really a good idea and neither are functions which single return values with accepting arguments.. so you need to plan your PHP application to use both concepts correctly.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.