Forum Moderators: coopster

Message Too Old, No Replies

Re-order the array

         

FiRe

3:19 pm on Oct 27, 2007 (gmt 0)

10+ Year Member



Array
(
[0] => Array
(
[name] => Another Fantastic Product
[quantity] => 1
[price] => 15.00
[total] => 15.00
)

[1] => Array
(
[name] => Toy Product
[quantity] => 2
[price] => 13.78
[total] => 27.56
)

[2] => Array
(
[name] => Accessory Item
[quantity] => 5
[price] => 6.70
[total] => 33.50
)

[3] => Array
(
[name] => Mini Cooper
[quantity] => 1
[price] => 100.00
[total] => 100.00
)

)

If I remove "Toy Product" (key 1) how can I get "Accessory Item" to be come key 1 and Mini Cooper to become key 2? There must be a function for this somewhere...? Thanks

Little_G

3:29 pm on Oct 27, 2007 (gmt 0)

10+ Year Member



Hi,

You can reassign the variable that points to the array with the return value of array_values [php.net].

Andrew

Habtom

5:19 am on Oct 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This removes the second one in the array:

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, 1);

Array Splice [php.net]

Habtom