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?
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'];
}
精彩评论