1 Reply Latest reply on Sep 15, 2008 11:20 AM by ntsiii

    Rotate (Pivot) Array


      I have a single row being return from mysql as JSON encoding.
      I normally decode in to an array and then pass into an arraycolloction.

      This normally works, but now I have an issue, I'm returning 1 row, but dynamic number of columns

      I need to rotate the row so I end up with a 2 column array, column name -> value. The column names and count is dynamic and could be 2 or could be 50.

      Now you can get the length of an array is there any way of getting the width and looping through it to push the name value pairs into a new array.

      I tried a sample with two and I got undefined.

        • 1. Re: Rotate (Pivot) Array
          ntsiii Level 3
          Well, worst case is you will need to do it manually, using split and a for loop.

          What does you data look like? You said "1 row". does that mean:

          If so, split it into an array (if it is not already an array) then in a for loop, use the modulus operator to determine whether you are processing a name or a value.