I need to split an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brianshields@gmail.com

    I need to split an array

    array("a", "b", "c", "d", "e");

    I want to now be able to load "b" into a variable ($var) then print it
    out

    print $var

    thanks!

  • brianshields@gmail.com

    #2
    Re: I need to split an array

    Oh and is it possible to change the delimeters of an array to pipes?

    Comment

    • Michael Fesser

      #3
      Re: I need to split an array

      .oO(brianshield s@gmail.com)
      [color=blue]
      >Oh and is it possible to change the delimeters of an array to pipes?[/color]

      Hmm? What delimiters?

      Micha

      Comment

      • Daniel Tryba

        #4
        Re: I need to split an array

        brianshields@gm ail.com wrote:[color=blue]
        > array("a", "b", "c", "d", "e");
        >
        > I want to now be able to load "b" into a variable ($var) then print it
        > out
        >
        > print $var[/color]

        It seems to me like it is time to RTFM. You should lookup arrays
        (http://nl.php.net/manual/en/language.types.array.php) and assignment of
        variables (like example 12-11 on`
        http://nl.php.net/manual/en/language...s.external.php)

        Comment

        • Daniel Tryba

          #5
          Re: I need to split an array

          brianshields@gm ail.com wrote:[color=blue]
          > Oh and is it possible to change the delimeters of an array to pipes?[/color]

          No, atleast not like: array("a"|"b");

          You could use an intermediate string and explode that into an array, see
          example 2 on http://nl.php.net/manual/en/function.explode.php

          Comment

          • Mostly Harmless

            #6
            Re: I need to split an array


            <brianshields@g mail.com> wrote in message
            news:1105493560 .155845.327620@ c13g2000cwb.goo glegroups.com.. .[color=blue]
            > array("a", "b", "c", "d", "e");
            > I want to now be able to load "b" into a variable ($var) then print it
            > out
            >
            > print $var
            >[/color]

            array basics.

            $var1 = array("a", "b", "c", "d", "e");
            $var2= $var1[1]; //element at index 1 contains "b"
            echo $var2;



            Comment

            • Jeffrey Silverman

              #7
              Re: I need to split an array

              On Tue, 11 Jan 2005 17:36:43 -0800, brianshields wrote:
              [color=blue]
              > Oh and is it possible to change the delimeters of an array to pipes?[/color]

              Delimiters appear in strings. Delimiters in arrays is meaningless.

              You are getting array usage confused a little. You don't "split" an
              array! An array is formed when you "split()" a string, however.

              examples:
              <?php
              $str = "a,b,c,d,e, f";
              $ary = split(",", $str);

              echo $ary[2]; // Outputs "c"
              ?>

              <?php
              $ary = array("a","b"," c","d","e");
              $str = join(",",$str); // puts array together into a string
              echo $str; // Outputs "a,b,c,d,e"
              ?>

              later...
              --
              Jeffrey D. Silverman | jeffreyPANTS@jh u.edu
              Website | http://www.newtnotes.com

              Drop "PANTS" to reply by email

              Comment

              • brianshields@gmail.com

                #8
                Re: I need to split an array

                Thanks! I do RTFM and i get lost. Newb. what can i say. Thanks for
                spending an extra 5 minutes and explaining it.

                Comment

                Working...