728x90
SMALL
#php
#How to create PHP
Sometimes it is necessary to automatically create variables according to a schedule rule. It seems that such a variable is called a floating variable, but I'm not sure if it's an official term.
When I try to create a flow variable, I have to put the variable in when creating the variable name. For example, if you wanted to put the name $var in your variable name, you would do:
${$var}
Below is an example of adding a serial number to the variable name. Put the value of the array into a variable with a serial number and print using that variable.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Coding Factory</title>
<style>
p {
font-family: "Consolas", monospace;
font-style: italic;
font-size: 1.3em;
}
</style>
</head>
<body>
<?php
$ary = array( "A", "B", "C" );
for ( $i = 0; $i < count( $ary ); $i = $i + 1 ) {
${ "ary_" . $i } = $ary[ $i ];
}
?>
<p><?php echo $ary_0 ?></p>
<p><?php echo $ary_1 ?></p>
<p><?php echo $ary_2 ?></p>
</body>
</html>
728x90
LIST
'PHP' 카테고리의 다른 글
[PHP] PHP/operators/increase operator, decrease operator (0) | 2022.08.13 |
---|---|
[PHP] PHP/operators/comparison operators (0) | 2022.08.08 |
[PHP] PHP/operators/arithmetic operators (0) | 2022.08.08 |
[PHP] PHP/operator/assignment operator (0) | 2022.08.04 |
[PHP] PHP / Grammar (0) | 2022.08.02 |