Answer the question
In order to leave comments, you need to log in
How to make the output more correct in php?
Hello.
A question.
I am doing etude programming in php. That is, I just want to learn the language for myself. Now I am engaged in input and output of information.
And so.
The code.
-------------------------------------------------- ------------
<?php include 'config.php'; ?>
<?php include 'dbconfig.php'; ?>
"/>
......
--------------------------------------- --------------------
I display the description in two ways: By the
contents of the files
1st file
<?PHP
define ("description", "description1");
?>
2nd file.
<?PHP
$config = array (
'description' =>
?>
The question itself.
To what extent is it reasonable, correct, etc. the use of such constructs in programming. As for the output information itself and the contents of the files?
Answer the question
In order to leave comments, you need to log in
an array is better than a constant - it can be manipulated.
constant - usually for paths or some values that should not change inside the script.
In the context in which you use in the example, i.e. description or "description", it may not be entirely appropriate to set a constant.
A simple example:
appropriate:
here you set a constant for the number Pi, for example, up to the sign you need. This is immutable data. A good reason to be constant.
appropriate:
in this case, it is also appropriate, because M52B20 engines from BMW have a volume of 2 liters, they left the assembly line with just such a code and such a volume. And nothing will change that. Convenient to use as a constant for quick access.
Continuing the topic of cars, now an example with an array:
$bmwE36 = array (
'year' => '1996',
'color' => 'deepblue',
'engine' => BMW_M52B20_ENGINE,
'type' => 'sedan',
);
define ("SEDAN", 4);
define ("CUPE", 3);
define ("UNIVERSAL", 5);
$bmwE36 = array (
'year' => '1996',
'color' => 'deepblue',
'engine' => BMW_M52B20_ENGINE,
'type' => SEDAN,
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question