Jump to content


Photo

Explain what this does?


  • Please log in to reply
2 replies to this topic

#1 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 07 October 2006 - 09:31 PM

<?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
 }
?>

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

The rest of it I do understand.

Thanks.

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 07 October 2006 - 09:45 PM

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

so:

<?php
$first = 'dog';
$second = 'cat';

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

echo $animaldog;
echo $animalcat;
?>

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 07 October 2006 - 09:55 PM

Ah thats what I thought. But I've never seen it before until today. Thank you





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users