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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:11:22+00:00 2026-05-14T00:11:22+00:00

Given this function: > function Get-ArrayOfArrays() { (1,2),(3,4) | % { $_ } }

  • 0

Given this function:

> function Get-ArrayOfArrays() {
    (1,2),(3,4) | % { $_ }
}

I’d expect the return type to be an array of arrays. However, it appears that the inner arrays are being expanded into the pipe:

> Get-ArrayOfArrays | % { $_.GetType().Name }
Int32
Int32
Int32
Int32

In fact, running the pipe inline will produce these results:

> (1,2),(3,4) | % { $_ }
Object[]
Object[]

I’ve found that if I use the return keyword inside the foreach, I can achieve the desired result:

> function Get-ArrayOfArraysWithReturn() {
    (1,2),(3,4) | % { return $_ }
}

> Get-ArrayOfArraysWithReturn | % { $_.GetType().Name }
Object[]
Object[]

This behavior seems to be “If returning from a function with uncaptured objects, and those objects happen to be arrays, then expand them”. Is this one of those “do-what-is-useful-most-of-the-time” design decisions? Or am I missing something else?

  • 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-14T00:11:23+00:00Added an answer on May 14, 2026 at 12:11 am
    (1,2),(3,4) | % {$_}
    

    results in your function outputting (1,2) and (3,4) – the same as this function would:

    function foo { 
        1,2
        3,4 
    }
    

    The kicker is that each of these arrays have their content’s unrolled (flattened) again as part of the process of a function outputting objects e.g.:

    PS> foo | %{$_.GetType().Name}
    Int32
    Int32
    Int32
    Int32
    

    This is similar to what you see on the host when you execute this:

    PS> 1,2
    1
    2
    

    The array is unrolled such that each element of the array is displayed. The following should do what you want:

    function Get-ArrayOfArrays() { 
        (1,2),(3,4)
    }
    

    When (1,2),(3,4) hits the function output it is unrolled once, outputting (1,2) and (3,4). Another technique you can use to work-around collection unrolling is to wrap a collection within another single element collection using the , operator to preserve the shape of the original collection e.g.:

    PS> function foo { ,((1,2),(3,4)) }
    PS> foo | gtn
    Object[]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're not alone! We have used both, mistakenly starting with… May 17, 2026 at 2:22 am
  • Editorial Team
    Editorial Team added an answer Here's a quick version of the "rather easy" solution rkhayrov… May 17, 2026 at 2:22 am
  • Editorial Team
    Editorial Team added an answer A CSS injection is nearly as good as script injection.… May 17, 2026 at 2:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Given this ugly method: public function convert_cell_value( $val, $type ) { if($type == 'String')
Given this: [ (A,A122); (A,A123); (B,B122); (B,B123); (C,C122); ] Is there a standard function
I want to use this function to get contours and within these contours, I
I intended for this function to call my MVC action method that returns a
Given a string and a number, this function will produce all possible combinations of
Given this code sample: complex.h : #ifndef COMPLEX_H #define COMPLEX_H #include <iostream> class Complex
I have this problem that I probably understand but don't know how to handle,
Given this harmless little list: >>> lst = ['o','s','s','a','m','a'] My goal is to Pythonically
I have a function whose purpose is to list the folders within the images
I'm working on an old-school image warp filter. Essentially, I have a 2D array

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.