Questions tagged [associative-array]

An associative array is an abstract data type composed of a collection of unique keys mapped to a collection of values.

Filter by
Sorted by
Tagged with
1 vote
1 answer
17 views

Can I declare typed associative array and then use it as typed by key object?

So, I have such an associative array structure: type CellT = { name: string; value: number }; type AssociativeArrayT = { [key: string]: CellT[] | AssociativeArrayT; }; const myObject: ...
Kirill Kazakov's user avatar
-1 votes
4 answers
79 views

Push a static associative element into all subarrays on a known level with a known parent key

I have a dynamically generated PHP multi-dimensional array as follows: Array ( [uid_1] => Array ( [sub_1] => Array ( [sub_sub_1] => Array ( [id1] => ...
Adrien Hingert's user avatar
-1 votes
1 answer
42 views

Change an array to an associative array in php to get key value pairs accordingly [duplicate]

I have a php script that returns the images(or files) in a directory. The final output is a json of file names. Below is the code of of what I have now and the result. <?php $files = array(); $...
winfred adrah's user avatar
-1 votes
0 answers
15 views

What is the scope of associative arrays in shell script and how to use its content outside of the scope? [duplicate]

Below is the program where I am using associative arrays as a storage which will be used later in a program. For which I have used 3 steps: Initialization populating values in it using it for ...
Vikas Singh's user avatar
0 votes
2 answers
79 views

iteration on a mix of array and associative

I have the following script: declare -A as1 declare -A as2 declare -a arr=() declare -A sup as1[file]="file1" as2[file]="file2" echo "test: ${as1[file]} ${as2[file]}" ...
learning-man's user avatar
2 votes
1 answer
38 views

is declare -A explicit declaration mandatory in associative arrays in Bash?

I have defined a bash associative array without the explicit declare -A command. But I am not sure if it really is the associative array since I read somewhere without the declare -A, the array is ...
masrur's user avatar
  • 23
0 votes
0 answers
58 views

How to access the last element of a bash associative array?

I am trying to access the last element of a bash associative array using the below code: # Declare an associative array declare -A myAssocArray # Add key-value pairs to the associative array ...
masrur's user avatar
  • 23
2 votes
2 answers
132 views

Bash - Sort the keys of an associative array in-memory in ascending order?

This Bash function is part of a script that i've recently wrote (following below is a minimal working example of the script with sample data, including an invocation of the function): #!/bin/bash ...
programings's user avatar
1 vote
1 answer
69 views

how to create array with associative array in other array php [duplicate]

I´m trying to create this structure to send data to API $metaDataList = [ [ "key" => "item_description0", "value" =&...
scorpions77's user avatar
3 votes
2 answers
67 views

Anomalous test -v results with bash associative array

Ran across this apparent anomaly. Test code: ( set -x declare -A a=() for i in x "'" '"' do a[$i]= test -v a[$i] && true done : "${!...
flabdablet's user avatar
  • 3,627
-1 votes
3 answers
76 views

Question About Multiple Entries In Bash Associative Array

Update As multiple comments have pointed out, associative arrays are not available / supported in Bash 2 or Bash 3. Closing this thread. See below for how we solved the Problem that we were trying to ...
D159's user avatar
  • 261
0 votes
4 answers
92 views

Remove key value pairs from an nested associative array where the value is null or " " or [] [duplicate]

I've the following array: $variables = [ "id" => "discountCodeID", "test" => null, "codeDiscount" => [ "code" => "...
Wakil Ahmed's user avatar
  • 1,051
0 votes
1 answer
51 views

Have a problem when I trying to convert an associative array to a JSON form php and pass to Python

My purpose is create a simple associative array and encode it to JSON this in PHP, after that I want to pass to a python script and this information decode into a dictionary, so for that I created ...
DeivDev97's user avatar
1 vote
1 answer
41 views

['']='': bad array subscript when declaring empty string key with empty value

How can I declare an associative array with something like declare -A ENV_JOBS=( [""]="" ["staging"]="staging-job-name ["dev"]="dev-job-name" ) ...
Yen's user avatar
  • 597
0 votes
0 answers
40 views

error when trying to print associative array element in smarty template

I have smarty 4.3 and php 8.1. I have this php array: array(4) { ["username"]=> string(16) "[email protected]" ["realname"]=> string(4) "blah" [&...
raphael75's user avatar
  • 3,032
0 votes
0 answers
14 views

PHP associative vs numeric arrays [duplicate]

While working with arrays, I came to a fundamental question about arrays in PHP: $ar1 = [ '0' => 1, '1' => 2 ]; $ar2 = [ 1, 2 ]; print_r($ar1 === $ar2); // 1 So, does this mean, that numeric ...
tweekz's user avatar
  • 189
1 vote
1 answer
140 views

Is it possible to iterate systemverilog associative array with non-int index type through VPI c function?

For example // test.sv class cls; int b; endclass module m cls testObj; int map[cls]; initial begin inst = new; inst.b = 10; map[cls] = 12; $VPIcall; end ...
tarik jhin's user avatar
1 vote
0 answers
17 views

Comparing two 2d arrays in php codeigniter4 and having issues in calculation of column totals and identifying duplicate values

I am working on project where I am uploading two excel files and able to get the files data in 2d associative arrays. I want to calculate the total of 2 rows if it exists only on array1 and not ...
Alex's user avatar
  • 21
0 votes
1 answer
34 views

Can i use variable in mutli level array naming [duplicate]

<?php $array['a']['b']['c']['d'] = "foo"; $many = ['b']['c']; echo $array['a']$many['d']; ?> Is there any way to make this work? I have try with {} around but i cannot make it work. ...
Mario Boulanger's user avatar
0 votes
3 answers
191 views

Using Variables to add to Bash Dictionary

Trying to create a dynamic set of Key-Value pairs through a series of for loops that basically pull from a JSON file to create a series of arrays that are then iterated through to define the key-value ...
Davis Sayer's user avatar
0 votes
3 answers
51 views

Unable to convert indexed array to associative array in php

The array $digit now has data in this form : 'numbers' => array ( 0 => '1,2,3', ) But I need that array in the below shown form: 'numbers' => array ( 0 => 1, 1 => 2,...
M G's user avatar
  • 27
0 votes
2 answers
32 views

Append an array with an array without any overwriting

I'm trying to create an array that looks like below. $arr = array( 'post_type' => 'smart_contract', 'post_status' => 'publish', 'author' => $user_id, '...
ratib90486's user avatar
0 votes
2 answers
30 views

Adding key-value pair to array conditionally adds the key with a null value to the array

I am working on an api that requires a json script, but I am making it so I can use the api on my website. The issue I am stuck on and struggling to find an answer for is when the array is 'compiled'. ...
Ether0p12348's user avatar
0 votes
2 answers
135 views

map or unordered_map in C++?

I'd like to count occurrences of a pre-known set of chars in a string of text. My intuition is to create a std::map with those chars as values and values initialised at 0, like so: unordered_map<...
Daniel Maxwell's user avatar
1 vote
2 answers
299 views

Dynamic array of queue and associative array

int c[][$][int]; I am trying to understand memories in depth. I was just wondering whether a 3D dynamic array with queue and associative array is possible or not? I am able to make 2D dynamic array ...
xxxl_eet's user avatar
1 vote
1 answer
42 views

Why am I getting warnings about a TypeScript multidimensional array that works?

I have an array of people stored in a multidimensional associative array. Each person belongs to a place and each place belongs to a timezone. I set up my variable like this: interface ...
StevenTakata's user avatar
-2 votes
1 answer
39 views

Parsing nested Values of AC list of Associative Arrays PHP

Issue New to PHP, trying to parse the values of an associative array that is in a list in PHP. I come from a Pythonic background and am faced with refactoring a code I wrote in Python to a PHP CLI ...
Terry Brooks Jr's user avatar
0 votes
2 answers
49 views

js: way to merge associative array with common keys value

I need to implement a javascript fx to merge associative array that may have a non defined structure. I mean that sometimes i need to merge [ { name: 'Stefano', age:46 }, { name: 'Name2', age:...
Stefano Radaelli's user avatar
0 votes
0 answers
41 views

How to add one-to-many correctly with an array field in sequelize?

So I have a user which can many many modules. The user table has a module fields which is an array of module_id. I think I should do a one to Many association. Is it correct? so I did the associations ...
FaFa's user avatar
  • 364
1 vote
1 answer
85 views

php reading kodi/xbmc movie nfo files

I am working on a php script to parse the movie nfo and tv nfo files that kodi generates/uses. However I have problems with getting some of the children properties (not sure if this is the correct ...
crosenblum's user avatar
  • 1,907
2 votes
1 answer
128 views

associative array initialization via string and without declare

I want to have a global associative array, that is filled at several locations and I can not get it to work to initialize the array with the content of a string without using the declare -A -g over ...
roediGERhard's user avatar
0 votes
2 answers
124 views

How do I define an associative array as a function param using zsh?

I'm using zsh 5.8.1 with mac OS Ventura and I'm trying this: #!/bin/zsh typeset -A foo=( [apple]="red" [banana]="yellow" ) echo $foo[apple] # Ok! prints "red" ...
Adrian Guerrero's user avatar
0 votes
1 answer
51 views

Error calling a function with an associative array in Bash

I'm trying to make a kind of class in Bash using an associative array. I have this code (in classes.sh): person () { # Define class properties name=$1 age=$2 # Define class methods ...
Enlighten Me's user avatar
0 votes
0 answers
10 views

Need to find a search for a value in an array and return a corresponding value from a tab separated file

I've been trying to figure out how to take the following sample data, put it in an array, search the array for something and return something else on the same line as the something searched for. The ...
Joe H's user avatar
  • 1
0 votes
1 answer
100 views

Groovy create Map from list

I tried to create Map (or associative array) in Groovy from two files with list, but the result is not what I expected. def componentsFile = "WORKSPACE/Components" def linksFile = "...
macder's user avatar
  • 161
0 votes
2 answers
33 views

Duplicate keys from the first entry, wrapping the rest of the keys into values

I'm newbie in jolt and I trying to transform the following JSON Headers can be different in different json. I really need a spec based on special characters like *,@,&,$ I'll be eternally grateful ...
Abroshka's user avatar
1 vote
1 answer
42 views

How to match independent arrays to convert them into array of objects

don't know how to use jolt's transformations such as shift、default、modify-default-beta. I have the following array value as input : { "a": [ [ "1", "2", ...
bertin's user avatar
  • 23
1 vote
1 answer
42 views

Jolt Transformation: Un-nest object of form "key":{"value":"xyz"} to "key":"value"

I need to unwrap JSON objects in order to reduce the nesting of input like [ { "key1": { "value": "abc" }, "key2": { "value":...
Benjamin Fach's user avatar
2 votes
1 answer
57 views

Sort Associative PHP Array By Number Then By String

I have an associative array in PHP that is created from a SQL Query. I've been sorting by just one column, but now I need to change the code to sort by two columns. The two columns consist of a FLOAT ...
Kompalisky87's user avatar
0 votes
4 answers
82 views

Get key (not index) from qualifying row in an associative array of associative arrays

Here my array: $array = [ 'key1' => [ 'first' => 'azerty', 'second' => 'qwerty' ], 'key2' => [ 'first' => 'hello', 'second' => 'world' ...
Kozame's user avatar
  • 289
-3 votes
1 answer
49 views

php: why is $row[0] not returning anything? [closed]

I am converting all my php scripts due to moving to a new server. I am stumped as to why $row[0] is not working. I am correctly getting $row populated as an array, and if I run a foreach on it, I get ...
Rick's user avatar
  • 1,760
1 vote
2 answers
60 views

Transpose a multidimensional array with variable depth (2 levels and 3 levels)

I need to restructure an array containing data in 2 levels and 3 levels. All of the values should be grouped by their indexes, but I need to maintain associative relationships. Sample input: $...
Adrian Costache's user avatar
-1 votes
1 answer
164 views

Zsh: Creating associative array from yaml file using yq

The real case: Every time I set up my environment, I'd like to check and – create if are not existing – certain environment variables. So, instead of doing it manually all the time, I thought it would ...
user1146081's user avatar
0 votes
0 answers
63 views

Map integers, that have the same population count (popcount), to continuous indexes (of an array)

I would like to cache some values for repeated uses. In temporal accesses, these cached values can be identified by integers (keys) that have the same population count (popcount). For example (...
Jeremy Wong's user avatar
0 votes
2 answers
389 views

zsh on MacOS: how to create an associative array (hash table) from the from two column-like scalars?

I have two scalar values in the form of columns: % echo $key hom doc fam echo $val 'home' 'Documents' 'Family' and I want to create associative array from them. I'm aware about the method of ...
user1146081's user avatar
0 votes
0 answers
65 views

Twig - Merge associative array deep

I'm trying to use merge function in Twig to add a new key : value element deep in an associative array. The key/value item I want to push is this deep element['something']['another_thing'] In ['...
Damien Letellier's user avatar
-1 votes
1 answer
49 views

I am new to Programming. I am stuck in adding the elements of an associative array taking 10 elements each time

I have tried the following way; but can it be done in any other way? <?php $arr = array( "text"=>"1,1,1,1,1,1,3,4,4,4,2,2,4,3,5,5,5,5,5,5,5,5,2,4,3,3,2,3,3,3,4,3,3,3,3,3,...
Ankur Guha's user avatar
0 votes
1 answer
192 views

Rust safe const iterable associative array

I would like to create a structure that's something like a compile-time immutable map with safely checked keys at compile-time. More generally, I would like an iterable associative array with safe key ...
Nick's user avatar
  • 158
1 vote
1 answer
1k views

How to get last Key or Value in Kotlin Map collection

How can I get the last key or value in a Kotlin Map collection? It seems like it cannot be done by using an index value.
Raj Narayanan's user avatar
0 votes
0 answers
36 views

AWK printing single array indices with other text [duplicate]

Trying to print array element and other stuff but awk doesnt print array element if something going after that awk -F, 'FNR==NR{tag[$1]=$2; next} ($1 in tag) {print tag[$1], $0}' OFS=, tags.csv ...
Ivan's user avatar
  • 31

1
2 3 4 5
64