Having a brain freeze over a fairly trivial problem. If I start with an array like this:
$my_array = array(
1 => [
"id" => 1,
"weight" => 0
],
2 => [
"id" => 2,
"weight" => -1
],
3 => [
"id" => 3,
"weight" => 0
],
4 => [
"id" => 4,
"weight" => -1
],
);
and i will do a function that move the keys of the array to key + 'weight'. So the result gona be like this:
$my_array = array(
1 => [
"id" => 2,
"weight" => -1
],
2 => [
"id" => 1,
"weight" => 0
],
3 => [
"id" => 4,
"weight" => -1
],
4 => [
"id" => 3,
"weight" => 0
],
);
What is the most efficient way to do this?
weighttopositionin-between the two. So a combination ofarray_mapandusortshould do the trick.[]. There's no point usingarray()instead