wondering if it's possible to reorder a php array based on given keys, currently I have an array that looks like this:
array:4 [▼
0 => array:3 [▼
"to" => "test"
"name" => "name"
"type" => "custom"
]
1 => array:4 [▼
"to" => "test 2"
"name" => "name 2"
"type" => "page"
"target" => "test"
]
2 => array:4 [▼
"to" => "my link"
"name" => "something"
"type" => "custom"
"target" => "_blank"
]
3 => array:4 [▼
"to" => "https://github.com/"
"name" => "github"
"type" => "custom"
"target" => "_parent"
]
]
On the frontend I'm using sortableJs to allow users to reorder the items to their liking, when the onSort event is fired I collect all of the ids inside of the sortable container and send it to the php function.
the data that sortable send looks like this
array:4 [▼
0 => "0"
1 => "2"
2 => "1"
3 => "3"
]
Where the value is the order that they're supposed to be in, so based on this data the original array would need to be this
array:4 [▼
0 => array:3 [▼
"to" => "test"
"name" => "name"
"type" => "custom"
]
2 => array:4 [▼
"to" => "my link"
"name" => "something"
"type" => "custom"
"target" => "_blank"
]
1 => array:4 [▼
"to" => "test 2"
"name" => "name 2"
"type" => "page"
"target" => "test"
]
3 => array:4 [▼
"to" => "https://github.com/"
"name" => "github"
"type" => "custom"
"target" => "_parent"
]
]
I've been thinking about this but can't seem to figure it out.