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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:44:35+00:00 2026-06-02T06:44:35+00:00

total noob here. I’ve an array which looks like: Array ( [15] => Array

  • 0

total noob here. I’ve an array which looks like:

Array
(
    [15] => Array
      (
        [0] => Array
            (
                [id] => 5216
                [name] => Grow your own Irish Shamrock gifts set
                [ordered] => 473
                [image] => FunShamrockPot.jpg
            )

        [1] => Array
            (
                [id] => 5217
                [name] => Irish Shamrock Seeds
                [ordered] => 357
                [image] => FunShamrockSeed.jpg
            )

        [2] => Array
            (
                [id] => 5759
                [name] => Ireland Fleece with Shamrock Badge
                [ordered] => 1
                [image] => IrelandFleeceShamrocks.jpg
            )

    )

    [31] => Array
      (
        [0] => Array
            (
                [id] => 5081
                [name] => Tartan Guinness Flat Cap
                [ordered] => 356
                [image] => GuinnessTartanFlatCap.jpg
            )

        [1] => Array
            (
                [id] => 4894
                [name] => Black signature emblem Guinness baseball hat
                [ordered] => 176
                [image] => GuinnessSigBBHat.jpg
            )

The array is called $products and I’m trying to just print out the first five arrays in each top array (if that makes sense) in other words, array[15]<– first five arrays under 15, array[31]<– first 5 arrays in here.

the code I’m trying is:

foreach($products as $key=>$value) {
    array_slice($value, 0, 5);
    foreach($value as $product) {
        echo $product['name'] . '<br/>';
    }
    echo '<br/>';
}

I can’t figure out why array_slice won’t work, what am I doing wrong?

  • 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-02T06:44:36+00:00Added an answer on June 2, 2026 at 6:44 am

    The problem is that array_slice does not modify the input array, you need the return value:

    foreach($products as $key=>$value) {
        $sliced = array_slice($value, 0, 5);
        foreach($sliced as $product) {
            echo $product['name'] . '<br/>';
        }
        echo '<br/>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey! Total CakePHP noob here. Updated at bottom / This is sort of a
Total noob question, but here. CSS .product__specfield_8_arrow { /*background-image:url(../../upload/orng_bg_arrow.png); background-repeat:no-repeat;*/ background-color:#fc0; width:50px !important; height:33px
Ok.. total noob question. I always thought that when I saw a URL like
Total noob question here, but not finding the answer via search. What is the
Total Haskell noob here. I have a simple function, and a main. I don't
well...just about all I needed to say...lookie here, I'm a total noob in web
Total noob question. I am building a simple photoblog in Rails which consists of
OK, total noob question here. I'm toying around with Silverlight, and need to connect
Total OO noob question here. I have these two methods in a class private
Total, embarassing noob here, so here goes nothing: if you wanted to create a

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.