I am writing a function that returns an id, name pair.
I would like to do something like
$a = get-name-id-pair() $a.Id $a.Name
like is possible in javascript. Or at least
$a = get-name-id-pair() $a["id"] $a["name"]
like is possible in php. Can I do that with powershell?
PowerShell ArraysArrays in PowerShell can contain one or more items. An item can be a string, an integer, an object, or even another array, and one array can contain any combination of these items. Each of these items has an index, which always starts (sometimes confusingly) at 0.
An array is a data structure that is designed to store a collection of items. The items can be the same type or different types. Beginning in Windows PowerShell 3.0, a collection of zero or one object has some properties of arrays.
An array, which is sometimes referred to as a collection, stores a list of items. A hash table, which is sometimes called a dictionary or an associative array, stores a paired list of items.
PHP treats all arrays as associative, so there aren't any built in functions.
also
$a = @{'foo'='bar'}
or
$a = @{} $a.foo = 'bar'
Yes. Use the following syntax to create them
$a = @{} $a["foo"] = "bar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With