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.
3,067
questions
0
votes
0
answers
12
views
bash access associative array creates unbound variable [duplicate]
I've looked for solutions for accessing an associative array and found some relevant solutions on SO here. But no matter which method I try, I've found that if the element doesn't exist in the array ...
0
votes
0
answers
15
views
Wordpress - If Menu plugin - Custom visibilty rules in navigation menu bar
I am using https://wordpress.org/plugins/if-menu/ to show/hide certain menu items in menu bar list only if device is mobile.
The problem is it recognizes even tablets as mobiles.
To tackle this ...
0
votes
0
answers
16
views
PHP: Sorting a specefic key of an associative multidimensional array [duplicate]
i want my foreach loop test specefic $key of "age"from my associative decoded json data for example and ascending or descendig sort whole array by value of "age" can anyone help ...
0
votes
1
answer
63
views
How to group the nested array based on id?
Basically I have an associative array from the database like below,
persons = [
[id=>1, name=>adam, hobbyId=>x, hobbyName=> swim],
[id=>2, name=>brian, hobbyId=&...
0
votes
1
answer
41
views
Php grouping values if find duplicate other value key [duplicate]
I have this in while loop of my query fetch
And i want to regroup values if find occurence in prefix key
while(($arr = $_opDB->fetch_assoc($result)) != FALSE){
if(!array_search($arr['...
-1
votes
0
answers
23
views
How do iterate through this API call which gives me this JSON and associative array
"limit": 1000,
"adminusers": [
{
"username": "admin",
"auth_type": "Local",
"id": ...
0
votes
1
answer
29
views
Need help traversing through associative array PHP and making HTML table [closed]
Array
(
[total_count] => 10
[limit] => 1000
[adminusers] => Array
(
[0] => Array
(
[username] => admin
...
3
votes
2
answers
61
views
Do latter keys in an hash assignment from an array always override earlier keys?
Given this:
%h = (a => 3, b => 4, a => 5);
Imperically $h{a} == 5 holds true, but are there cases where $h{a} == 3 because of internal dictionary hashing or some other perl-internal behavior?...
0
votes
2
answers
46
views
Creating PL/SQL procedure to fill intermediary table with random data
As part of my classes on relational databases, I have to create procedures as part of package to fill some of the tables of an Oracle database I created with random data, more specifically the tables ...
1
vote
3
answers
58
views
How to get an array with states as key and cities as value from the json array in PHP [duplicate]
I have a json array which is somethig like this:
[
{
"CITY": "Horseheads",
"STATE": "NY"
},
{
"CITY": "Auburn&...
0
votes
0
answers
31
views
Loop over associative array to generate separate section and header markup based on key value in PHP [duplicate]
I have an indexed array of associative arrays like so:
array
0 =>
array
'topic' => 'Topic 1'
'question' => 'Topic 1, Question 1'
'answer' => no'
1 =>
...
0
votes
1
answer
24
views
Populating associative array values from other arrays in PHP [duplicate]
If I have separate arrays w/ values for "questions" and "answers" like so:
var_dump($questions)
array (size=2)
0 => string 'Question 1' (length=10)
1 => string 'Question ...
0
votes
2
answers
43
views
How to assign an associative array from a string in a function
I want to populate an associative array with successive output from an instruction.
With attention for the quotes, I first tried this
declare -A aa
dict='[TAG1]="VALUE 1" [TAG2]="VALUE ...
2
votes
0
answers
42
views
In PHP, is it possible to post an empty string as an array key, based on the input name?
The following input will produce $_POST['test']['a'] === "1"
<input name="test[a]" value="1">
The following input will produce $_POST['test'][0] === "2"
&...
0
votes
0
answers
13
views
Rearrange SQL query result in php to display multiple rows on one line
I have some php code that performs an sql query and uses a while loop to displays the rows of the result in a table. The code basically looks like this:
$results = $_dbh->query($sql);
while($row = ...
0
votes
2
answers
85
views
How to use(read) value from associative array during jq map?
I am reading aws ssm parameters via jq with json, and want to put them into a yaml file after some processing and alias mapping.
I have one associative array of mapping parameter name to some internal ...
0
votes
3
answers
130
views
How to read yaml file into bash associative array?
I want to read into bash associative array the content of one yaml file, which is a simple key value mapping.
Example map.yaml
---
a: "2"
b: "3"
api_key: "somekey:...
-1
votes
2
answers
24
views
PHP - Combine Two Arrays based on a key property value of the first array - improve code
I have two associative arrays below
The first one has information about the stock status of that day, this is store in a different database.
The second array has the information of the product like ...
1
vote
1
answer
34
views
rewrite key value in foreach [duplicate]
I have such array and I need to convert it:
Array
(
[0] => Array
(
[0_mass] => 0.00
[0_arm] => 287.02
[0_max_limit]...
-1
votes
2
answers
50
views
Associative Array in foreach with array-key and indexing number as well
//how can i get indexing number of this array without using any external varible
$ageRanges = ['name' => '17', 'min'=> null, 'max'=> '17'];
foreach($ageRanges as $key => $ageRange){printf(...
1
vote
1
answer
29
views
Filter php array and keep only oldest data on duplicate data
I've an array in PHP that can have multiple same labels, but creation date for each one is different. I try to filter my array and keep only old created data when duplicates labels exists in my array.
...
0
votes
4
answers
86
views
Using Associative arrays
I'm trying to access a position of a associative array which is inside of another array.
Here is my array:
Array
(
[order_data] => stdClass Object
(
[id_order] => 2
...
0
votes
0
answers
14
views
Referencing an associative array added as value inside another associative array
I have the following structure:
$positions = array();
$salaries = array();
$registers = ['Position' => $positions, 'Salary' => $salaries];
Since I created the positions and salaries ...
1
vote
2
answers
94
views
php array performance when adding elements one by one vs when adding all of the data at once
for the sake of simplicity i will put a simple example, i have an $array and few key and values that i wanna add to this array.. what is better primarily from performance perspective:
to add all of ...
0
votes
0
answers
55
views
In Azure, can I create a mapping at runtime?
I'm trying to loop over an array of group names and I want to dynamically get the IDs of those groups so that I can assign roles to them.
I just learned I can set a variable at runtime in a pipeline ...
0
votes
1
answer
36
views
Compare keys and values from two arrays and print all values including duplicates
I have already the values from another array, my problem is how can I show the duplicate values in an array?
I have tried this using array_intersect_key and don't know how to show duplicates and ...
1
vote
0
answers
16
views
How to force bash to assign string as key in array [duplicate]
I found some strange behaviour of Bash while working with associative array. It all assigns to the position 0 in array. Any way to force it to keep the string as key? Here is the code and output..
...
0
votes
2
answers
80
views
How does select column into associative array from table work in Oracle database
when I am multiplying the index by 3 instead of one, three rows are getting inserted into the associative array and also it seems that the 2nd and 3rd rows have no value present.
So how are the rows ...
-1
votes
1
answer
63
views
How can I get the list of indices an associative array has? [closed]
I have an associative array in awk, and I can iterate over the values of the array using (e.g.) for (v in ARRAY) ....
However I want to iterate over the indices (keys) of the array instead.
...
0
votes
1
answer
39
views
How to select random value in an associate array in php
I have a data(Associate array) that I got from mysql database which looks like this
$data=[
["id"=>"1", "words"=>"words 1"],
["id"=>&...
0
votes
1
answer
27
views
Associative array in Login system
I have this foreach loop where it has 3 if else statement. First is it logins sucessfuly, Second is it has a wrong password and the Third one is it detects that the usernames does not exist in an ...
-1
votes
2
answers
42
views
How can I sort PHP associative array by keys that contains ranges
I found lots of answers on stackoverflow and other sites relating to arrays but they don't seem to be working with my problem.
I have the following code:
Array (
"-10 to -5" => Array ( ...
0
votes
1
answer
35
views
How can I create an array of variables based on an associative array's value in PHP?
Given the following array
(
0 => array(
'orders_messaging_info_id' => '1',
'column_name' => 'message_route',
'column_info' => 'internal',
),
1 => array(
'...
0
votes
2
answers
39
views
In PHP, for a specific key in an associative array, find identical keys and combine values into a single string variable
I have found many references for similar questions on SO but nothing close to what I'm trying to do. I have this array output:
0: {id: 1000012, kp_uid: 100000570, assigned_uid: 'tim.hughes@sampleco....
1
vote
1
answer
154
views
Create an array containing multiple key: value pairs, where the value is an array
What I want to achieve is something like this :
let bigArray = [ key1 => [], key2 => [], key3 => [] ];
Where bigArray would be an array containing in this case 3 arrays with specific names/...
0
votes
4
answers
74
views
get the maximum price of the associative array in php
I have the following array
$data = [
[
'name' => 'Electric Khodro',
'price' => 12912
],
[
'name' => 'Iran Khodro',
'price' => 15218
],
[
'name' => 'Iran arghaam',
...
0
votes
2
answers
33
views
Addaing a value to an existing key in associative array
So I'm trying to add a value to an existing key in an associative array. Key 'message' is for displaying different errors based on validation.
$formStatus = [
'success' => false,
'...
0
votes
0
answers
66
views
How can i make a form with dynamic array and with removable inputs
I want to make a form with html css js that support this feature
Problem:
Imagine i have an array like this:
[0=> [armature => 10,format => 2, concrete => 31],1=> [armature => 31,...
0
votes
4
answers
259
views
How can I merge two associative arrays and preserve the global order of the entries?
I have two arrays like this:
$arr1 = ['a' => '1','b' => 2];
$arr2 = ['h' => 'c','j' => '3'];
And I want to merge them to this result:
$newArr = ['a' => '1','h'=>'c','b'=>2,'j' =&...
0
votes
3
answers
246
views
How can I use keys and values from jq to generate a bash associative array?
From Json structure, I want a specific dictionary. From key's color yellow or red, I add id value.
[
{
"id": "9b058640",
"type": "db",
"color&...
0
votes
1
answer
32
views
redux - async storage with associative array [duplicate]
I am trying to use associative arrays with redux and to store them in the async storage to retrieve on loading the app.
With redux it works very well I have real quick access to the values and can map ...
0
votes
1
answer
25
views
Bash associative arrays be initialized in a (...) list?
Can bash associative arrays be initialized in a (...) list similarly to non associative arrays? Format?
Updating to give an answer using the comments.
Yes, the format depends on the version of bash. ...
0
votes
1
answer
28
views
Need help to convert Associative Array to key=>value pair
My Code:
global $wpdb;
$row = $wpdb->get_results( "SELECT * FROM `wp_employee`", ARRAY_A );
print_r ($row);
Output:
Array(
[0] => Array(
[job_id] => 1
...
0
votes
2
answers
37
views
Trying to sort two different columns of a text file, (one asc, one desc) in the same awk script
I have tried to do it separately, and I am getting the right result, but I need help to combine the two.
This is the csv file:
maruti swift 2007 50000 5
honda ...
0
votes
1
answer
60
views
How to set "parent_id" of child element of multidimensional array from parent id
I need to display the parent id in the child's array. I have the id of the parent (uuid), now I need to add a new key in the array of the child (parent_id) with the uuid of the parent.
I have the ...
0
votes
1
answer
21
views
Cat strings from file and compare it with associative bash array
I create associative array for example
declare -A vars=(["Test array here"]="POOLING TESTPOOL ")
And i have file with multiple lines which want to compare with array values and if ...
1
vote
1
answer
58
views
Why do the `man bash` pages state the `declare` and `local` `-n` attribute "cannot be applied to array variables", and yet it can?
Why does local -n work on array variables when the manual explicitly says it does not? Is the manual wrong? Is this relying on some sort of bash "undefined behavior?" Is the manual out-of-...
0
votes
1
answer
48
views
How to get value from constant file array based on key in php?
I have one file which is constants inside this file i have one array i want to call that array key into another file,can you please help me to fix the issue..?
constants.php
<?php
namespace App\...
2
votes
2
answers
4k
views
Dealing with PHP 8.1 warning for undefined array key
We are upgrading to PHP 8.1. A new feature is that an undefined array key throws a warning.
Unfortunately this interferes with the ability to easily use associative arrays such as $_SESSION variables. ...
1
vote
1
answer
50
views
How to Recursively find secondary profiles and merge into primary one
I have a sample array, in which I would like to find the secondary ones and recursively check the secondary one until all secondary profiles gets unset from PHP array.
Here is the example array.
$...