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

  • Home
  • SEARCH
  • 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 412799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:07:15+00:00 2026-05-12T18:07:15+00:00

I have an array full of sub arrays. I need to break apart the

  • 0

I have an array full of sub arrays.
I need to break apart the first array at a given line number, and then insert a new line, and then combine them all back into their original structure.

This is what im working with now

$csvpre = explode("###", $data);

$i = 0;
$bgc = 0;

    foreach ( $csvpre AS $key => $value){
        $info = explode("%%", $value);
        $i++;
        if($i == "1"){
            echo "<tr bgcolor=#efefef><td></td>";
                foreach ( $info as $key => $value ){ echo "<td>$value</td>"; }
            echo "</tr>";

        } else {

            if($bgc&1) { $bgcgo = "bgcolor=\"#b9b9b9\"" ;} else { $bgcgo = "bgcolor=\"#d6d6d6\""; }
            echo "<tr $bgcgo><td></td>";
            echo "<td><input type=button value=\"clone #$i\"></td>";
            $j = 0;
                foreach ( $info as $key => $value ){ 
                    $j++;

                        if($j != 8){
                            echo "<td>$value</td>";
                        }else{
                            echo "<td><textarea name=ddesc[]>$value</textarea></td>";
                        }
                }
            echo "</tr>";
            $bgc++;
        }       
    }

What i need to create, is a function that will take a value for $i, say 10, and at that line split the array into two pieces $arraya and $arrayb. Then i need to combine them back together while including a new line…

pseudo code

$startarray = array(Line0, Line1, Line2, Line3, Line4);
$splitline = 2;
$arraya = splitup($startarray, $splitline);
$arrayb = splitdown($startarray, $splitline);

ArrayA would then consist of Line0, Line1, Line2. And ArrayB would consist of Line3, Line4.
Then we run the magic function.

$newline = "Line2.5";
$newarray = somefunction($arraya, $newline, $arrayb);

And $newarray would then look like

Line0, Line1, Line2, Line2.5, Line3, Line4
  • 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-12T18:07:15+00:00Added an answer on May 12, 2026 at 6:07 pm

    If I understand your question correctly, array_splice() can do that all in one go:

    $array = array('Line0', 'Line1', 'Line2', 'Line3', 'Line4');
    array_splice($array, 3, 0, 'Line2.5');
    print_r($array);
    

    which outputs:

    Array
    (
        [0] => Line0
        [1] => Line1
        [2] => Line2
        [3] => Line2.5
        [4] => Line3
        [5] => Line4
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we have array of arrays: tree_limbs = Array.new tree_limbs << %w(1 2 3
I have an array full of objects which need to be sorted, however I
I have a array that is full of image objects, I need to be
Need to have an array full of random numbers within range. Code: void fillArray(int
I have a line chart and the full array of data is attached to
I have setup an array full of words as objects. I am trying then
I have an array full of random content item ids. I need to run
I have an array full of patterns that I need matched. Any way to
I have an array unsortedPosts full of dictionaries, which look like this if I
I need to extract the name of the direct sub directory from a full

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.