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
0
votes
2 answers
Questions about array/associative array
i am trying to create a 3-level array then retrieve the 3th level array data but somehow i get this.
$project = array();
$project[] = "name";
$project[] = "id";
$project["id"] = "AXA";
$project["id"]["AXA"] = "a new project";
echo…

Genjo
- 133
- 1
- 1
- 8
0
votes
1 answer
How to get a certain value from an associative table in sql
I have two tables and one table that associates these two.
Table A has two columns (pk,name)
Table B also has two columns (id,name)
Table AB has three columns (pk(FK of A), id(FK of B), date)
How can I write a select to retrieve A.name, B.name and…
user1897748
0
votes
2 answers
PHP Recursion with Associative Array (Menu structure)
I've been banging my head against a wall today. I have a mysql table that has a list of menu items which have a recursive parent/child relationship. I need to create an associative array that matches it.
Here is my code, and below it is an…

gone
- 1,079
- 5
- 13
- 31
0
votes
2 answers
PHP associative array keys not being set
In this snippet $opt is an xpath node created from this tag:
//...
$this->permissions = array();
$key = $opt['name'];
$value = $opt[0];
echo $key . "=" . $value;
$this->permissions[$key] = $value;
echo…

Buddy Wagner
- 13
- 5
0
votes
1 answer
PhP associative error array based on dynamic key=>values
Here is a class I've began writing to add a new user to my database via a registration form. Everything has worked fine up until I try to do back-end checking to see if required values are not provided. Here is the code...
class User
{
//Basic Login…

Highspeed
- 442
- 3
- 18
0
votes
1 answer
Im getting an undefined index error from my function
function get_frequencies( $a )
{
$get_frequencies = array();
foreach( $a as $k => $v )
{
$get_frequencies[$v]++ ; //this is the line causing the error
}
return $get_frequencies;
}
/*Get Flip function involking and testing */ …

Martin Bullman
- 3
- 1
0
votes
1 answer
Creating an associative array in PHP from sql results, for json
I'm trying to create an associative array from sql results for json_encode.
here's my code:
$timelineQuery = "SELECT * FROM timeline_table";
$contentQuery = "SELECT * FROM content_table";
$picQuery = "SELECT * FROM pic_table";
$sql =…

user2025462
- 11
- 3
0
votes
2 answers
Removing an item from a session associative arrays in php
I am really stuck with this. It is an array within an array such as:
Array ( [0] => Array ( [item] => product1 [unitprice] => 15 [quantity] => 1 ) [1] => Array ( [item] => product2 [unitprice] => 15 [quantity] => 1 ) )
I have tried to remove a…
0
votes
2 answers
Targeting a specific part of an associative (one-demonsional) array?
I want to try to swap the first and last index's of this array:
'dad',
'Josh' => 'son',
'Jamie' => 'mom',
'Jane' => 'daughter',
'Jill' => 'daughter'
);
?>
So that it…

Peter
- 73
- 2
- 8
0
votes
1 answer
How to sort php array if your left place in array is for keys and right for values?
I had problem with array_push so I needed to make numeric array instead of associative. But, as I was doing it, I always pushed 2 values:
first was the key to search (ID of object in table)
second was some value that was given to object with…

Tommz Tenodi
- 15
- 3
0
votes
1 answer
Javascript: Generate random numbers and store in multi dimensional array
I'm trying to generate random numbers and store the number in multi dimensional array o(need help of examples)
[ 8, 52, 9, 34, 51, 19 ]
[ 8, 52, 9, 34, 51, 19 ]
[ 8, 52, 9, 34, 51, 19 ]
What I want to achieve is to generate a sets of 6 numbers…

Vish
- 383
- 2
- 8
- 25
0
votes
3 answers
Assigning values to a new array
I am new to associative arrays and I have this code below. I would like to assign the values for prop and sumprop[prop] to a new array, prop1 and prop2. Appreciate some help here.
var name = new Array();
var amount = new…

user1033038
- 141
- 3
- 15
0
votes
2 answers
PHP function which checks how many integers are in associative array
I need help to solve the question that was on the exam at my college. It goes something like this: ‘’Function in PHP which checks how many integers are in associative array, data is not transmitted over the arguments, but as a global variable’’. …

Kora
- 3
- 1
0
votes
1 answer
swapping positions in first dimension of a multidimensional array
So I've got the following array: http://pastebin.com/raw.php?i=AazcQUbG
In a part of code outside of the function below, I loop through this particular ordered array (ordered by the second dimension's 'team_points') and determine if there is a tie…

user1645914
- 371
- 6
- 23
0
votes
4 answers
My Associative array is multi dimensional, and i can't figure out why. PHP
Hi all. I'm currently in the middle of developing a login class that handles the user login. I get my array list back from the DB by creating it as an object with the following code:
$dBquery = new Selection();
…

Jay
- 1,033
- 1
- 18
- 31