This tag is used mostly regarding associative arrays (but better use tag "associative-array" for that) and sometimes in the mathematic sense of tag "associativity", the associative property of binary operations.
Questions tagged [associative]
435 questions
2
votes
1 answer
Insert into multiple tables from a CSV
I have a CSV that's formatted like this:
MasterSKU, Location, Notes, SubSku1, SubSku2, SubSku3, SubSku4, SubSku5, ...
I have two tables in a MySQL database designed like this:
CREATE TABLE `master_sku` (
`id` int(11) NOT NULL AUTO_INCREMENT,
…

wirikidor
- 33
- 3
2
votes
1 answer
Associative array lookup in memory
Its just a question out of curiosity. Suppose we have an associative array A. How is A["hello"] actually evaluated , as in how does system map to a memory location using index "hello"?

Carlin
- 23
- 2
2
votes
2 answers
Looping AWK associative array
I am using a column in one file to look up values in another file. The second file is very large and I would like to find all the values in a single pass with awk. I have tried doing this with an associative array, but am stumped how to get the…

jeffpkamp
- 2,732
- 2
- 27
- 51
2
votes
1 answer
Issue with associative array in Bash script
I was trying to demonstrate the use of an associative arrary to gather counts. It is working in the while loop, but it appears to have lost all its information after the while loop. What am I doing wrong? All echo statements except for the one in…

user2836927
- 37
- 1
- 5
2
votes
3 answers
Use associative arrays with preg_replace
In the documentation for preg_replace it says you can use indexed arrays to replace multiple strings. I would like to do this with associative arrays, but it seems to not work.
Does anyone know if this indeed does not work?

Nic Hubbard
- 41,587
- 63
- 251
- 412
2
votes
3 answers
Create a copy of a result row
How can I copy an array that has other associative arrays in it?
I am talking about a result set returned from a mysql_fetch_assoc.
So say I have a structure like this...
connect
$result = query;
while ($row = mysql_fetch_assoc($result)) {
…

abhishekbh
- 539
- 5
- 15
2
votes
1 answer
Creating 2-D matrix in php
The thing is I have to create a 2D matrix in php where each row and column must have a key. I tried to do this but what happens is that a 2-D array is created which does not resemble a matrix. I used the following…

5lackp1x3l0x17
- 349
- 2
- 7
- 14
2
votes
1 answer
multidimensional array json_decode (first level)
I have a JSON file like this:
{
"numeric1": {
"id": "numeric1",
"name": "alphanumeric1",
"key": "alphanumeric2",
"expire": "alphanumeric3",
"status": true,
"ads": true
},
etc...
}
with…

PurpleFoxy
- 1,107
- 3
- 12
- 17
2
votes
4 answers
Create associative array from 2 columns in PHP and MySQL
Can I make an associative array from two columns? I want column A as key and column B as value.
-------------
| id | name |
-------------
| 1 | sky |
-------------
| 2 | space |
I want a function that make result like…

user2586454
- 360
- 1
- 4
- 9
2
votes
1 answer
Add value from one associative array to another based on condition
So far I have three arrays which return values from the database like this (after much formatting)
[0]=>array(
[0]=>'Apr', [1]=> 1),
[1]=>array(
[0]=>'May', [1]=>2),
[2]=>array(
[0]=>'Jun', [1]=>23)
The second…

AyB
- 11,609
- 4
- 32
- 47
2
votes
2 answers
Comparing two associative arrays
I started learning Perl last week.
I have an associative array from a file containing 'tokens' - Just a bunch of numbers.
I have another associative array from an SQL Database containing 'tokens'.
I'm wanting to see if any tokens in the file are NOT…

abstrakt
- 57
- 1
- 8
2
votes
1 answer
Associative array sort numeric
I have an associative array in following format.I need to sort the array in descending order and sort the array with same value as ascending order.
$numArray = array();
$numArray[0]['Word'] = 'One';
$numArray[0]['Number'] =…

JAI
- 119
- 3
- 7
2
votes
1 answer
how to assign associative array value in a smarty 2.x template without php script
how to assign associative array value to a variable say,
{* $a = array('key1'=>123) *}
{assign var="a.key2" value=234}
without pre-assigning in php script or using a {php} tag?

konghou
- 557
- 7
- 20
2
votes
1 answer
Seeking efficient associative bitset hash
Suppose you have an ordered sequence of bitsets b1, b2, b3, ..., bN.
Is there an efficient bitwise operator hash calculation which can be used to generate hashes which is also associative?
In other words, what is a recommended hashing function…

KomodoDave
- 7,239
- 10
- 60
- 92
2
votes
1 answer
PHP - Return array of parents from multidimensional associative array for breadcrumb list
I'm trying to create dynamic breadcrumbs from an array. So I can add to the array and not have to manually update the breadcrumbs.
Okay, here's a snippet of my array: (It won't go much deeper)
$menu = array(
'Dashboard' => array(
…

thisispiers
- 109
- 9