Assignment questions Unit-3
Assignment questions Unit-3
$color=Array[“red”,”yellow”,”pink”];
Foreach($color as $a)
{
Echo $a.”<br>”;
}
?>
SvariableName =value;
Example:
Sname = "Srikanth"
3.Variable Assignment:
PHP does not require to declare a variable before using it. We can simply
assign a value to a variable and PHP will automatically create the
variable and assign the value to it.
We use the assignment operator (=) to assign a value to a variable.
Example: $name= "Srikanth";
$age = 40;
4.Data Type Conversion: PHP is a dynamically-typed language, which
means that the data type of a variable is determined at runtime based on
the value assigned to it. For example, if we assign a string to a variable,
and later assign an integer, PHP will handle the conversion
automatically.
Example:
$name = "Srikanth"; // This is a string variable
$name =40; // This is an integer variable
PHP variables are loosely typed, which means that they can hold
different types of data, and their type can change during the execution of
a program.
Example:
<?php
$color=”yellow”
$num=10;
Echo $color;
Echo $num;
$color =”orange”;
Echo $color;
In the example above, we first declare and assign values to the variables
$color and $num. Later, we change the value of $color and echo its new
value.