creating variables in a loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Damo

    creating variables in a loop

    Hi,
    I want to create variables in a loop, each with a different name. Here
    is the loop i'm using:


    if (is_array($attr ibs)) {
    echo "Attributes : <br />";
    while(list($key ,$val) = each($attribs)) {
    echo $key."has the value".$val."<b r>";

    }
    }

    I want to create a variable with the name of each $key and contain the
    value in $val.
    Is this possible?

  • gosha bine

    #2
    Re: creating variables in a loop

    Damo wrote:
    Hi,
    I want to create variables in a loop, each with a different name. Here
    is the loop i'm using:
    >
    >
    if (is_array($attr ibs)) {
    echo "Attributes : <br />";
    while(list($key ,$val) = each($attribs)) {
    echo $key."has the value".$val."<b r>";
    >
    }
    }
    >
    I want to create a variable with the name of each $key and contain the
    value in $val.
    Is this possible?
    >
    Possible (see http://www.php.net/manual/en/function.extract.php) but
    pretty pointless. What's wrong with just array?


    --
    gosha bine

    extended php parser ~ http://code.google.com/p/pihipi
    blok ~ http://www.tagarga.com/blok

    Comment

    • Damo

      #3
      Re: creating variables in a loop

      Cheers for the help. That did the trick

      Comment

      • jussist@gmail.com

        #4
        Re: creating variables in a loop

        On Jun 4, 10:23 pm, Damo <cormacdeba...@ gmail.comwrote:
        Cheers for the help. That did the trick
        If that did the trick, you did something wrong designwise ;-)

        But sometimes quick solutions are needed, and good design is not the
        target / withing scope.

        --
        Jussi
        Deep abstraction kills strong typing.

        This domain name has been registered with Gandi.net. It is currently parked by the owner.



        Comment

        Working...