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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:22:27+00:00 2026-05-26T05:22:27+00:00

I have a multi-dimensional array and what i want is in each second degree

  • 0

I have a multi-dimensional array and what i want is in each second degree of array values limit should be set to 4 only. Like i have a array of type:

Array
(
 [test2] => Array
    (
        [0] => Array
            (
                [application_id] => 405275016
            )
        [1] => Array
            (
                [application_id] => 405275016
            )

        [2] => Array
            (
                [application_id] => 303198288
            )

        [3] => Array
            (
                [application_id] => 303841592
            )

    )

[test3] => Array
    (
        [0] => Array
            (
                [application_id] => 289267216
            )

        [1] => Array
            (
                [application_id] => 303198216
            )

        [2] => Array
            (
                [application_id] => 405275016
            )

        [3] => Array
            (
                [application_id] => 303198288
            )

        [4] => Array
            (
                [application_id] => 303841592
            )

        [5] => Array
            (
                [application_id] => 311430400
            )

        [6] => Array
            (
                [application_id] => 318096216
            )

        [7] => Array
            (
                [application_id] => 320256352
            )
    )

)

and what i want that if the inner arrays value exceed 5 count it should not add any further values to it. i have to format this above array to something like:

Array
(
 [test2] => Array
    (
        [0] => Array
            (
                [application_id] => 405275016
            )
        [1] => Array
            (
                [application_id] => 405275016
            )

        [2] => Array
            (
                [application_id] => 303198288
            )

        [3] => Array
            (
                [application_id] => 303841592
            )

    )

[test3] => Array
    (
        [0] => Array
            (
                [application_id] => 289267216
            )

        [1] => Array
            (
                [application_id] => 303198216
            )

        [2] => Array
            (
                [application_id] => 405275016
            )

        [3] => Array
            (
                [application_id] => 303198288
            )

        [4] => Array
            (
                [application_id] => 303841592
            )
    )

)

here in second array array last 3 arrays were truncated in order to take only 5 count as a value. I have tried many a methods but none achieved this.

Any idea on how can i achieve this will be highly appreciated ??

  • 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-26T05:22:28+00:00Added an answer on May 26, 2026 at 5:22 am
    foreach ($array as $k => $v) { // Loop outer array
      for ($i = 5; isset($array[$k][$i]); $i++) { // Loop inner array, starting at element #5
        unset($array[$k][$i]); // unset all elements >=5
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi dimensional array. The only actual values (other than other arrays)
I have an multi-dimensional array that I want to send to a PHP script
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
If I have a multi dimensional array in PHP like so... [0] => Array
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
I have what amounts to a multi-dimensional array. int[][][] MyValues; What I want is
I have a multi-dimensional array similar to the example below that I want to
I have a multi-dimensional array that looks like this: The base array is indexed
I have a multi-dimensional array called my_ids_and_names It should probably be a hash but

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.