Jump to content

Explain what this does?


SharkBait

Recommended Posts

[code]
<?php
while (!feof($handle)) { # Checks the File pointer integer returned by fopen.
              $buf = fgets($handle, 1096); # Returns a String from config, 1098 bytes long.
              list($k,$v)=split('=', $buf); # Create a list of variables and assign string values by splittin$
              $v = trim($v); #Remove Whitespace from $V

            if ( $k ) {
                      $config{$k} = "$v";
            }
    #      echo "#" .$k .$v ."<br>";
    #      echo $config
}
?>
[/code]

Well the part I have not seen before is the line [code=php:0] $config{$k} = "$v";[/code]  I've never seen curley braces used on a variable. What is it for?

The rest of it I do understand.

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/23304-explain-what-this-does/
Share on other sites

the {} when use with a variable means that the variable's name can be dynamic/set on the fly.

so:

[code]
<?php
$first = 'dog';
$second = 'cat';

$animal{$first} = 'woof';
$animal{$second} = 'miaw';

echo $animaldog;
echo $animalcat;
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.