getting values in an array of arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • speralta@progressivetrail.org

    getting values in an array of arrays

    Hi,

    The following is the output of a print_r on an array. The value of
    element[0] is itself an array. How do I access the elements in the
    second array?

    Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
    [Beaverton] =Beaverton ) )

    I've tried to set $c[] = $city[0], but this just outputs the same
    result.

    Thanks,

    Sal

  • Michael Fesser

    #2
    Re: getting values in an array of arrays

    ..oO(speralta@p rogressivetrail .org)
    >The following is the output of a print_r on an array. The value of
    >element[0] is itself an array. How do I access the elements in the
    >second array?
    $foo[1st level][2nd level][3rd level]

    Micha

    Comment

    • speralta@progressivetrail.org

      #3
      Re: getting values in an array of arrays

      On Feb 7, 9:35 am, Michael Fesser <neti...@gmx.de wrote:
      .oO(spera...@pr ogressivetrail. org)
      >
      The following is the output of a print_r on an array. The value of
      element[0] is itself an array. How do I access the elements in the
      second array?
      >
      $foo[1st level][2nd level][3rd level]
      >
      Micha
      Hi Micha,

      Thanks for the suggestion, It was the step in the right direction that
      I needed to resolve the problem. The problem was that I was trying to
      access the elements in the associative array by index numbers rather
      than as a key/value pair. This worked:

      foreach($city[0] as $key =$value) {
      echo $key.'='.$value ;
      }


      How do I get, in this example, the value of the array element with the
      key "vancouver" :

      Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
      [Beaverton] =Beaverton ) )


      Comment

      • Jerry Stuckle

        #4
        Re: getting values in an array of arrays

        speralta@progre ssivetrail.org wrote:
        Hi,
        >
        The following is the output of a print_r on an array. The value of
        element[0] is itself an array. How do I access the elements in the
        second array?
        >
        Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
        [Beaverton] =Beaverton ) )
        >
        I've tried to set $c[] = $city[0], but this just outputs the same
        result.
        >
        Thanks,
        >
        Sal
        >
        $myarray[0]['Vancouver']


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Rik

          #5
          Re: getting values in an array of arrays

          <speralta@progr essivetrail.org wrote:
          On Feb 7, 9:35 am, Michael Fesser <neti...@gmx.de wrote:
          >.oO(spera...@p rogressivetrail .org)
          >>
          >The following is the output of a print_r on an array. The value of
          >element[0] is itself an array. How do I access the elements in the
          >second array?
          >>
          >$foo[1st level][2nd level][3rd level]
          >>
          >Micha
          >
          Hi Micha,
          >
          Thanks for the suggestion, It was the step in the right direction that
          I needed to resolve the problem. The problem was that I was trying to
          access the elements in the associative array by index numbers rather
          than as a key/value pair. This worked:
          >
          foreach($city[0] as $key =$value) {
          echo $key.'='.$value ;
          }
          >
          >
          How do I get, in this example, the value of the array element with the
          key "vancouver" :
          >
          Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
          [Beaverton] =Beaverton ) )

          $city[0]['Vancouver']

          If you perhaps do not know the key names in advance you'll have to give us
          a little more insight in the actual purpose.
          --
          Rik Wasmus

          Comment

          Working...