Array to simple variables assignment

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

    Array to simple variables assignment

    Am I conflating PHP with another language (PERL maybe?) or can you do an
    assignment to $a, $b and $c something like ($a, $b, $c) = $array? The
    given sytax doesn't work nor does [$a, $b, $c] = $array. This leads me
    to believe in the conflation theory. If there is a syntax for this,
    could you please send me a manual reference for it?
  • Andy Hassall

    #2
    Re: Array to simple variables assignment

    On Tue, 25 Jul 2006 18:29:52 -0400, Bob Stearns <rstearns1241@c harter.net>
    wrote:
    >Am I conflating PHP with another language (PERL maybe?) or can you do an
    >assignment to $a, $b and $c something like ($a, $b, $c) = $array? The
    >given sytax doesn't work nor does [$a, $b, $c] = $array. This leads me
    >to believe in the conflation theory. If there is a syntax for this,
    >could you please send me a manual reference for it?
    Yes, you're closer to Perl with the first example, which is almost valid in
    that language, except it'd be @array not $array.

    PHP requires an extra word to do the same thing; see http://uk2.php.net/list


    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Noodle

      #3
      Re: Array to simple variables assignment


      Bob Stearns wrote:
      Am I conflating PHP with another language (PERL maybe?) or can you do an
      assignment to $a, $b and $c something like ($a, $b, $c) = $array? The
      given sytax doesn't work nor does [$a, $b, $c] = $array. This leads me
      to believe in the conflation theory. If there is a syntax for this,
      could you please send me a manual reference for it?
      $array = array($a, $b, $c);



      Comment

      • Bob Stearns

        #4
        Re: Array to simple variables assignment

        Andy Hassall wrote:
        On Tue, 25 Jul 2006 18:29:52 -0400, Bob Stearns <rstearns1241@c harter.net>
        wrote:
        >
        >
        >>Am I conflating PHP with another language (PERL maybe?) or can you do an
        >>assignment to $a, $b and $c something like ($a, $b, $c) = $array? The
        >>given sytax doesn't work nor does [$a, $b, $c] = $array. This leads me
        >>to believe in the conflation theory. If there is a syntax for this,
        >>could you please send me a manual reference for it?
        >
        >
        Yes, you're closer to Perl with the first example, which is almost valid in
        that language, except it'd be @array not $array.
        >
        PHP requires an extra word to do the same thing; see http://uk2.php.net/list
        >
        >
        Thank you.

        Comment

        • Bob Stearns

          #5
          Re: Array to simple variables assignment

          Noodle wrote:
          Bob Stearns wrote:
          >
          >>Am I conflating PHP with another language (PERL maybe?) or can you do an
          >>assignment to $a, $b and $c something like ($a, $b, $c) = $array? The
          >>given sytax doesn't work nor does [$a, $b, $c] = $array. This leads me
          >>to believe in the conflation theory. If there is a syntax for this,
          >>could you please send me a manual reference for it?
          >
          >
          $array = array($a, $b, $c);
          >

          >
          That is the opposite of what I wanted. The correct syntax, as pointed
          out by Andy Hassal is:

          list($a, $b, $c) = $array;

          Comment

          • Noodle

            #6
            Re: Array to simple variables assignment


            Bob Stearns wrote:
            Noodle wrote:
            >
            Bob Stearns wrote:
            >Am I conflating PHP with another language (PERL maybe?) or can you do an
            >assignment to $a, $b and $c something like ($a, $b, $c) = $array? The
            >given sytax doesn't work nor does [$a, $b, $c] = $array. This leads me
            >to believe in the conflation theory. If there is a syntax for this,
            >could you please send me a manual reference for it?

            $array = array($a, $b, $c);

            That is the opposite of what I wanted. The correct syntax, as pointed
            out by Andy Hassal is:
            >
            list($a, $b, $c) = $array;
            Fair Enough. I don't think I read your question correctly.

            Comment

            Working...