Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:17:59+00:00 2026-05-30T20:17:59+00:00

Possible Duplicate: PHP Insert at particular index Is it possible to to insert in

  • 0

Possible Duplicate:
PHP Insert at particular index

Is it possible to to insert in the middle of a linked list in php. If yes, can someone please provide me with the code of the function that implements it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:18:00+00:00Added an answer on May 30, 2026 at 8:18 pm

    Yes it is possible.

    function insertIntoMiddle($LinkedList, $NewItem)
    {
        // we will use current as a pointer to the current position in our list
        // if we arrive at the middle, we insert the $NewItem
        $currentIndex = 0;
        $currentItem = $LinkedList->getFirstItem();
    
        // calculate the middle of your list
        $middleIndex = floor($LinkedList->getLength() / 2);
    
        // Loop over the list until you get the item in the middle
        while (++$currentIndex < $middleIndex)
        {
            $currentItem = $currentItem->getNextItem();
        }
    
        // insert the $NewItem between $currentItem and the next
        $NewItem->setNextItem($currentItem->getNextItem());
        $currentItem->setNextItem($NewItem);
    
        // also setPreviousItem() if you have linked your list both ways
    }
    

    This is of course pseudo-code as you didn’t provide any example code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP method chaining? So I can remember seeing in some code examples
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” This code shows warnings
Possible Duplicate: insert multiple rows via a php array into mysql I know about
Possible Duplicate: PHP: the ultimate clean/secure function I have got this code when I
Possible Duplicate: E-mail validation in php? please help I have Ajax sign up form.
Possible Duplicate: How can I prevent SQL injection in PHP? This is the example
Possible Duplicate: PHP: self vs. $this What does $this-> mean in CakePHP? Please answer
Possible Duplicate: PHP 2-way encryption: I need to store passwords that can be retrieved
Possible Duplicate: PHP DateTime::days returns trash? Ok, I don't get this... Could someone explain
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I am just learning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.