Forum Moderators: coopster

Message Too Old, No Replies

Change $key type

Changing array Key type from string to int

         

trebian

5:35 pm on May 20, 2004 (gmt 0)

10+ Year Member



Hi folks. Is it possible to change the key value type in an array? I have an array that has string key values, for my purposes I need it to have int index so I could passthe array for a graph plot.

NOW LOOKS LIKE: (thanks to coopster):
array(6) { ["04-01"]=> int(0) ["04-02"]=> string(2) "32" ["04-03"]=> int(0) ["04-04"]=> int(0) ["04-05"]=> int(0) ["04-06"]=> int(0) }

I NEED IT TO LOOK LIKE:
array(6) { [0]=> int(0) [1]=> string(2) "32" [2]=> int(0) [3]=> int(0) [4]=> int(0) [5]=> int(0) }

REASON:
I am getting date value from a DB, and than doing an array_merge with another template to ensure that any missing month for a category get a zero in the correct sequence. Problem is that, the resulting array needs to have int index for the graphing utility to work.

TIA

Netizen

5:52 pm on May 20, 2004 (gmt 0)

10+ Year Member



What you need is array_values [php.net]. This will return all the values in the array into an array indexed by integer.

trebian

7:27 pm on May 20, 2004 (gmt 0)

10+ Year Member



Thank you, it worked beautifully!