A
A
Andrey Krivenko2015-09-09 21:27:45
JavaScript
Andrey Krivenko, 2015-09-09 21:27:45

How to change the value of a variable in PHP from another file?

I’ll immediately say a question from a beginner)) don’t judge strictly)))
There is a test.php file in it there is a variable:
<?$name = 'Ivan';?>
There is also another setting.php file
Question: What kind of php code should I write in the file setting.php which will allow you to change the value of the $name variable in another test.php file?
Thank you very much in advance!!!

Answer the question

In order to leave comments, you need to log in

6 answer(s)
V
Valentin, 2019-04-05
@Mestniydevil

If it's for your example, then so
console.log(backgraunig[i]);

U
UNy, 2019-04-05
@UNy

Are you trying to make a slider? If yes, then look at how it is implemented by others. In general, write a function that reacts to a click and transfers the id of the picture to the server. For example, you clicked on next, and next you have a picture with id=2, passed this value to the server, it found the corresponding picture and gave it back.

M
Maxim Timofeev, 2015-09-09
@webinar

www.php.su/articles/?cat=fs&page=005
Read. Without the code of your files, I can not advise more.

M
Michael, 2015-09-09
@scherbuk

<?$name="Vasya"?>

A
Andrey Krivenko, 2015-09-09
@ak-biznes

Yes, that's right, only it somehow needs to be specified from another file. I can just change the value of the variable myself)))

A
AlikDex, 2015-09-09
@AlikDex

settings.php file

<?php 
$config = [
  'name' => 'vasya',
  'test_conf' => 1,
];

test.php file
<?php 
require_once "settings.php"; // подключим массив с настройками.
foreach($config as $key => $value) { // преобразуем массив в переменные
   $$key=$value;
}
echo $name; // vasya
echo $test_conf; // 1
?>

this is if I correctly understood your task, based on the file names and attempts to make a variable substitution))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question