3,316 questions
4
votes
4
answers
118
views
Map unknown associative array element
How can I map an unknown value alongside other known values in bash using an associative array, so that:
#!/bin/bash
array=("foo" "foo" "bar" "something else" &...
2
votes
1
answer
83
views
Downside of NOT using quotes for keys of associative array?
Every example I have found tends to go aa["key"]="value" and even with constants, e.g.:
declare -rA aa=( ["lit1"]="value1" ["lit2"]="value2" ...
-1
votes
2
answers
215
views
How to deserialize ${aa[@]@K} into referenced associative array with no eval effect?
How can I reference an associative array and reassign its content from serialized string?
(The eval requirement is now spelled out explicitly in the title, but this is natural when it comes to ...
0
votes
2
answers
87
views
Create associative multidimensional array in a loop Python
I just started learning Python. I try to create a data structure from the file wg.conf
I'm stuck on creating an array Peers. I need to create multiple Peer entries inside that array.
Config file ...
1
vote
1
answer
86
views
Displaying individual rows with same key as part of larger associative array using PHP and HTML
I am trying to display data from multiple MySQL tables in individual text fields in an HTML form using PHP. Here are three sample tables from a database, followed by code that I am using to select ...
1
vote
1
answer
191
views
Why isn't PHPStan complaining about invalid array keys?
Here's the code:
<?php declare(strict_types=1);
/**
* @param array{key?: string} $options
*/
function hello($options)
{
var_dump($options);
}
hello([
'WRONG_KEY' => '...',
]);
I ...
3
votes
2
answers
199
views
What kind of implementation can I use for a static associative array on a vintage system with very limited resources?
I'm working on a project written in C that's going to be deployed on vintage systems with very limited resources. The target system has at minimum a 16 MHz Motorola 68030 processor with a 256 byte L1 ...
-7
votes
2
answers
91
views
Filter an array of arrays to remove rows where the entire payload is found inside another (potentially larger) row [closed]
I get an array of associative arrays of selected company's hierarchy combinations (Some hierarchy levels may be null).
For example, if the hierarchy goes division > department > team:
[
0 =>...
-4
votes
1
answer
138
views
Building nested array with foreach [closed]
I am trying to build an associative multidimensional array like this:
array(
[0] => Array(
Parent => Mr Smith,
Children => array(
Firstmane => Bob,
...
1
vote
1
answer
209
views
add JSON object keys and values to bash associative array
I want to loop through a JSON object and add the keys and values to a Bash associative array.
Here's my JSON object that is in a file named deploy.json.
"deploymentEnvs": {
"dev":...
0
votes
2
answers
80
views
Global associative array (hash) in the older bash-4
The following script works as expected for me on FreeBSD using bash-5:
function a {
declare -gA Seen
if [[ -v Seen[$1] ]]
then
echo "Saw $1 already"
return
...
-1
votes
1
answer
73
views
How to dynamically convert a string into (and revert from) UTF8 special font characters?
How to dynamically convert a string into (and revert from) UTF8 special font characters "on-the-fly" using PHP functions?
For example,
echo cvtIntoSpclUTF8FntChars('script', 'Hello, World!');...
1
vote
3
answers
117
views
Dlang associative array of an array of strings keyed by a string has unexpected behavior
The output from the following code does not behave how I think it should. It appears that making changes to the string array returned by testAA.require() does not reflect in the associative array. I ...
-1
votes
1
answer
52
views
bash syntax for accessing an associative array with a value from a different associative array
Good morning,
I have here:
declare A- accocArray1=(["a01"]=1 ["a02"]=2 ["a03"]=3)
declare A- accocArray2=(["b01"]=1 ["b02"]=2 ["b03"]=3)
...
1
vote
4
answers
114
views
Use flat array's values to generate an associative array whose keys and values are given a static prefix
Is there a shorthand for the following code:
$result = array_combine(
array_map(fn($elem) => "key_$elem", $array),
array_map(fn($elem) => "value_$elem", $array)
);
...
0
votes
2
answers
74
views
Map values between two arrays to generate a flat, associative array
I have two arrays, one is a list of status IDs and the corresponding numbers of records that are that status ID. The second array is the names of the statuses. I'd like to tie them together so I have ...
3
votes
2
answers
126
views
Handling Repeated Courses in GPA Calculation Script in Bash
I'm working on a Bash script to calculate GPA for students, taking into account courses that might have been repeated. My goal is to ensure that if a student retakes a course, only the latest grade is ...
0
votes
0
answers
55
views
Problem reading JSON values from file into array in javascript
I am writing a web application showing departures from a preselected station. An id of the selected station is saved as a coockie. A JSON file containing id's and full names is read into an array with ...
1
vote
2
answers
358
views
How do i iterate through an associative array in Bash where the values are arrays?
I wrote this code to loop through usernames and domains on my LAN. Sadly, the script prints nothing.
#!/bin/bash
construct_array_of_trgts() {
declare -A usrs_n_dmns
local -a guest_dmns
local ...
6
votes
1
answer
170
views
Why can't an associative Bash array be assigned with an array?
According to man bash it is possible to assign an associative array with a flat list of key-value pairs:
[…] or a list of words that is interpreted as a sequence of alternating keys and values: name=(...
0
votes
2
answers
156
views
Using custom class in vb.net dictionary
I want to create a dictionary of products where the id is key and the product parameters are custom class that contain the information about the products. It seems like I am storing the information ...
-1
votes
1
answer
218
views
Vuejs template : "Cannot read properties of null" but Array is defined
I want to display an array elements in my Vuejs template.
I am getting data from API, formatting them into an associative Array with a function and then trying to display in the template :
export ...
1
vote
0
answers
47
views
Associative array ( hash table, tree, etc ) benchmark tool?
Are there any tools for benchmarking associative arrays?
Should be able to benchmark different types of keys, sparse/dense, long/short, few/many .
Should perform operations insert, delete, query . ...
1
vote
1
answer
97
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: ...
-1
votes
4
answers
91
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] => ...
-1
votes
1
answer
62
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();
$...
0
votes
2
answers
91
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]}"
...
3
votes
1
answer
141
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 ...
0
votes
0
answers
120
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
...
2
votes
2
answers
181
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
...
1
vote
1
answer
143
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" =&...
3
votes
2
answers
123
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
: "${!...
-1
votes
3
answers
222
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 ...
0
votes
4
answers
145
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" => "...
1
vote
1
answer
306
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" )
...
0
votes
0
answers
75
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"
[&...
1
vote
1
answer
724
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
...
1
vote
0
answers
30
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 ...
0
votes
1
answer
39
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.
...
1
vote
3
answers
3k
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 ...
0
votes
3
answers
89
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,...
0
votes
2
answers
49
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,
'...
0
votes
2
answers
110
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'.
...
0
votes
2
answers
821
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<...
1
vote
2
answers
2k
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 ...
1
vote
1
answer
77
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 ...
-2
votes
1
answer
51
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 ...
0
votes
2
answers
92
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:...
1
vote
1
answer
201
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 ...
2
votes
1
answer
389
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 ...