I have been asked about this simple question by a student and I was greatly troubled because I cannot provide a sufficient answer to this. What I understood is that, a variable is just a container that holds a value. Aside from that, I cannot provide a logical explanation to them.
example:
I want to check if an age is minor or not. By using a variable, I will make it this way:
<?php
$age = 30;
if( $age > 18)
echo 'You are no longer a minor';
?>
But, without using a variable, I can make it this way:
<?php
if( 30 > 18)
echo 'You are no longer a minor';
?>
If the two scripts produce the same output, then why should we put it in a variable, for in fact, we can lessen the code of we'll not use a variable. And also, Is it necessary to put a value into a variable?
Does it affect the memory of a computer?