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 4054726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:36:43+00:00 2026-05-20T14:36:43+00:00

Back to my original question, on how to check if the next elem starts

  • 0

Back to my original question, on how to check if the next elem starts with a space, if it does, concatenate it to the previous elem. how would you deal with cases where the array has multiple levels.

[1] => Array (
    [1] => Packages
    [2] => Sources
    [3] =>  Reading package
    [4] =>  Sources
    [5] =>  More Sources
    [6] => volatile Sources
    [7] =>  volatile
)

To output:

[2] => Array (
    [1] => Packages
    [2] => Sources Reading package Sources More Sources
    [6] => volatile Sources volatile
)

Will do it for the first space.

for($i = 0; $i < count($array); $i++){
    if($array[$i][0] == ' '){
        if($i > 0){
             $array[$i-1] .= $array[$i];
             unset($array[$i]);
        }
    }
}
  • 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-20T14:36:44+00:00Added an answer on May 20, 2026 at 2:36 pm
    $t = array ( 'Packages',
                 'Sources',
                 ' Reading package',
                 ' Sources',
                 ' More Sources',
                 'volatile Sources',
                 ' volatile'
               );
    
    
    $n = '';
    foreach($t as $k => $v) {
        if (substr($v,0,1) == ' ') {
            $t[$n] .= $v;
            unset($t[$k]);
        } else {
            $n = $k;
        }
    }
    
    var_dump($t);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would you please help me getting back the typename of the original object put
i want the draggable object to revert back to its original position when i
I'm on OSX and want to switch back to my original zsh config from
I need to be able to reset an input field back to its original
Back in college I wrote a game where the computer would sleep for 1
Back in the days before Visual Studio Web Server we would host our local
SEE EDIT UPDATES BELOW. Original question has been modified! I have a working window
EDIT 3: I am maintaining the original question below for historical reasons. However, I
Coming off the back of this question here , is there a way to
Thanks for all your help - see blow original question, and my edit following

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.