0

Possible Duplicate:
array_splice() for associative arrays

I have an associative array with products data.

Array
(
    [0] => Array
        (
            [ID] => 1
            [Name] => Game 1
            [Price] => 19.95
            [Status] => active
        )
    [1] => Array etc..
)

How can I add a key to any location in the array and not just the beginning or the end? Eg. between intID and strName, or at the/beginning, or before enumStatus?

Community
  • 1
  • 1
Meddie
  • 571
  • 1
  • 7
  • 22
  • http://stackoverflow.com/questions/3353745/how-to-insert-element-into-array-to-specific-position ? – 472084 Sep 10 '11 at 10:45

1 Answers1

0

You can sort them or rewrite them, for example in foreach loop

$newarray = array();
foreach($array as $index => $data){
   $newarray[$index]['ID'] = $data['ID'];
   $newarray[$index]['Price'] = $data['Price'];
   $newarray[$index]['Name'] = $data['Name'];
   $newarray[$inedx]['Status'] = $data['Status'];
}
genesis
  • 50,477
  • 20
  • 96
  • 125