PHP Insert at particular index

前端 未结 3 351
北荒
北荒 2021-01-26 02:27

I want to move element of array present at 1st index to the 5th index in the array. How can I do that?

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-26 03:09

    Although there are currently at least 2 valid answers to the question you asked, an array is not the right the right data structure to hold a list which has frequent changes and where ordering is important. These solutions will start to get very slow as the size of the array increases.

    The right structure would be linked list, unfortunately AFAIK the bundled PHP implementation (splDoublyLinkedList) does nto support inserts either.

提交回复
热议问题