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.

An associative array (also associative container, map, mapping, dictionary, finite map, and in query-processing an index or index file) is an abstract data type composed of a collection of unique keys and a collection of values, where each key is associated with one value (or set of values). The operation of finding the value associated with a key is called a lookup or indexing, and this is the most important operation supported by an associative array. The relationship between a key and its value is sometimes called a mapping or binding. For example, if the value associated with the key "bob" is 7, we say that our array maps "bob" to 7. Associative arrays are very closely related to the mathematical concept of a function with a finite domain. As a consequence, a common and important use of associative arrays is in memoization.

See also

3174 questions
1
vote
1 answer

pass associative array value to $_get

I am trying to build a url query with an associative array like this: http://website.com/go.php?status=0&day=monday Here is the my code but it only returns the word array. $status = $_GET["status"]; $day= $_GET["day"] = array( "monday" =>…
Daniel
  • 4,202
  • 11
  • 50
  • 68
1
vote
2 answers

PHP how to loop through assoc array without replicating variables?

This would be easy to do with regular array with a simple for statement. EG: $b= array('A','B','C'); $s=sizeof($b); for ($i=0; $i <$s ; $i++) $b[$i]='your_face'; print_r($b); But if I use assoc array, I can't seem any easy way to do…
Anonymous
  • 4,692
  • 8
  • 61
  • 91
1
vote
2 answers

php loop through associative arrays

Editing this code here on Stackoverflow and I'm really near to get the result I need. So I have this code posted down here: $friends = $facebook->api('/me/friends'); if(!empty($friends['data'])){ $size =…
1
vote
4 answers

Array with associative values accessed numerically

I have an associative array that I might need to access numerically (ie get the 5th key's value). $data = array( 'one' => 'something', 'two' => 'else', 'three' => 'completely' ) ; I need to be able to…
Fanis Hatzidakis
  • 5,282
  • 1
  • 33
  • 36
1
vote
3 answers

Output mysql result as an array of the form (column name => possible values for column name)

I have database such as I want to create an associative array such that each att_name value is associated with its possible values from att_value: array('att_name' => array('att_value_1', 'att_value_2', 'att_value_3')) What is the best way to…
1
vote
2 answers

accessing the first elemnt in the associative array in php

I have the following sql that returns a row that is stored as an associative array in php select count(*) as a from "tablename" where columnname = "some"; I know that this sql is going to return only one row with one column, namely 'a', each time…
Shenoy Tinny
  • 1,315
  • 10
  • 22
  • 34
1
vote
1 answer

How to check if PHP associative arrays are equal, ignoring key ordering?

Say I have two complex nested arrays in PHP, like these: $a = array( "x" => array(4, 5, 6), "y" => array("z" => "foo", "q" => "bar") ); $b = array( "y" => array("q" => "bar", "z" => "foo"), "x" => array(4, 5, 6) ); (In this…
Walter Mundt
  • 24,753
  • 5
  • 53
  • 61
1
vote
1 answer

PDO prepared statement in PHP using associative arrays yields wrong results

I am working on a very small PHP and MySQL application. I have a class called User for manipulating user data in the database which contains a createUser method as shown below:- /** * Creates a new user record in the users table for a new user * …
Chetan Kinger
  • 15,069
  • 6
  • 45
  • 82
1
vote
2 answers

php foreach not showing first value in array

I have an array ($vEvents) as follows: Array ( [0] => Array ( [id] => 1174 [date] => 120411 [name] => DR. J 'Souled Out' ~ 9pm (No Cover) [pubId] => 44 [price] => ) [1] => Array ( [id] =>…
MaurerPower
  • 2,046
  • 7
  • 26
  • 48
1
vote
1 answer

How to convert javascript associative array to json and use later using parseJSON?

Look I want to do this: function MyObject() { this.attr1; this.attr2; this.attr3; } var myArray = new Array(); myArray["a"] = new MyObject(); myArray["b"] = new MyObject(); myArray["c"] = new MyObject(); var json_myArray = CONVERT_TO_JSON(…
CRISHK Corporation
  • 2,948
  • 6
  • 37
  • 52
1
vote
2 answers

How to loop through multidimensional associative javascript array?

I have 'multidimensional associative' javascript array (which in fact is object with properties as JS can't have native associative array): var multiArray={ AAA:"one", BBB:"two", CCC:{ 0:"xxx", 1:"yyy", 2:"zzz"} }; And i need to get such string…
1
vote
3 answers

PHP: Building array out of values of another, associative, multidimensional array

I have an array, let's call it $menus, that contains something like this: Array( [Main] => Array ( [menu_name] => Main [title] => Main Menu ) [Nav] => Array ( [menu_name] => Navigation [title] =>…
beth
  • 1,916
  • 4
  • 23
  • 39
1
vote
1 answer

Translating two dimensional associative jquery array to php array

I'm having problems translating my associative array that I create in jQuery to something I can access and use in PHP. I use the following to build an associate array: var colors = {}; $(this).find('input[name="color_id"]').each(function() { var…
Jon Rubins
  • 4,323
  • 9
  • 32
  • 51
1
vote
1 answer

Strange associative array with punctuation behavior

I have this simple code to count punctuation in a string. ie "there's 2 commas, 3 semi-colons..." etc. But when it sees an em-dash (—) it doesn't work. Note that it is not a hyphen (-), I don't care about those. Is there something special about…
jb.
  • 9,921
  • 12
  • 54
  • 90
1
vote
5 answers

How to extract data into associative array from HTML table using jQuery?

Suppose I have HTML like this,
adarsh
  • 6,738
  • 4
  • 30
  • 52
1 2 3
99
100
Hello A word
Bye A word
Tricicle