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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:56:59+00:00 2026-06-10T09:56:59+00:00

I have a normal, boring old array which has a lot of data in

  • 0

I have a normal, boring old array which has a lot of data in it. Let’s say the array is structured like this:

$myArray = array( 'a','b','c','START','d','e','f','END' );

Now, I need to select only the values that come after START, but before END. So, in this example, I need to select the values ‘d’, ‘e’, and ‘f’.

Here’s the tricky part; START will always exist, however END may or may not (this is how the data is returned from the server). If START and END both exist, then I just need the values inbetween the 2. if only START exists, then just select all the values from START until the end of the array. ‘START’ does not have a fixed index; its location changes depending on the data supplied from the server.

So what would be quick, relatively painless way to rip out these values in between 2 specified values, and then save them to a new array?

EDIT: The only implementation I was able to get functioning was the one provided by @nickb, further down in the comments. I have added it to this OP for ease of use for others.

array_shift( $array[0]); // Get rid of the 'count' element
$start = array_search( 'registered:current', $array[0], true);
$end = array_search( 'END', $array[0], true); // Change 'END' to whatever it is
$return = array_slice( $array[0], $start + 1, ($end ? ($end - $start - 1) : null));
  • 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-06-10T09:57:01+00:00Added an answer on June 10, 2026 at 9:57 am

    How about this?

    $end = array_search( 'END', $array, true);
    $return = array_slice( $array,
        array_search( 'START', $array, true) + 1,
            ($end ? ($end - count( $array)) : null)
    );
    

    If 'END' isn’t found, array_search() will return false, which causes the the 3rd parameter to array_slice() to be set to null, returning the remaining elements in the array, starting at 'START'. But if 'END' is found, you’ll get an array containing the elements between 'START' and 'END', as seen in this demo.

    Edit: Here is a simpler implementation that uses the indexes directly, which is based on Matt’s edit with some tweaks to make it not include the delimiter:

    $start = array_search( 'START', $array, true) + 1; // +1 to get rid of 'START'
    $end = array_search( 'END', $array, true);
    $return = array_slice( $array, $start, ($end ? ($end - $start - 1) : null)); // Omit 3rd param if 'END' is not found
    

    Edit: Final implementation:

    array_shift( $array[0]); // Get rid of the 'count' element
    $start = array_search( 'registered:current', $array[0], true);
    $end = array_search( 'END', $array[0], true); // Change 'END' to whatever it is
    $return = array_slice( $array[0], $start + 1, ($end ? ($end - $start - 1) : null));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a normal textbox in my application. I can paste data to it
I have a HTML table where some rows have a button like this: <td
I have a table like Id Value 1 Start 2 Normal 3 End 4
I have the following jquery mobile code: <div data-role=collapsible> <h3>I like to read a
I have normal WCF service with few methods. I would like to log some
I have normal sqlite database and want to use fts3. As mentioned in http://www.sqlite.org/fts3.html
I have a normal NavigationController. When i open one modalView (using segues) and dismiss
I have a normal asp.net page containing some code that I want to measure
I have a normal UINavigationController with a UIViewController contained in it, when my view
Imagine you have a normal table view where each row is an item on

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.