Questions tagged [associative]

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.

435 questions
2
votes
0 answers

In which case is an array faster

I have a huge list of objects (e.g. I call them messages). Every message contains an array (e.g. I name them user) with 2, 3 or 4 strings (userids). If I loop trough all messages I want to check in every message whence a userid is in the array or…
Biber
  • 709
  • 6
  • 19
2
votes
2 answers

How to use a number attached to a string in associative array

I have a card deck array: $cards = array("2_of hearts" => 2, "3_of_hearts" => 3, "king_of_hearts" => 10); And I want to echo the name of the card somewhere (example: 2_of_hearts) but also calculate something with the number attached to it, but I…
Jim L
  • 351
  • 2
  • 13
2
votes
8 answers

JS associative object with duplicate names

ok, so I have an object like: var myobject = { "field_1": "lorem ipsum", "field_2": 1, "field_2": 2, "field_2": 6 }; as you see there are duplicate names in the object, but with different values. If i go through it like (using…
2
votes
2 answers

how combine multiple arrays into a single associate array using the arrays as keys

I have 2 arrays that i would like to loop through and combine into an associative array. I would like to use the 2 arrays as the keys for the new associative array. I am new to php so any and all help would be appreciated. $id = array( 2, 4); $qty…
2
votes
5 answers

How to remove duplicate values from an associative array based on a specific value?

I have an array that looks just like that: array(3) { ["fk_article_id"]=> string(1) "4" ["first_name"]=> string(6) "Ulrike" ["last_name"]=> string(10) "Grasberger" } array(3) { ["fk_article_id"]=> string(1) "9" ["first_name"]=> string(5) "Frank"…
flhe
  • 341
  • 4
  • 8
  • 15
2
votes
1 answer

PHP Associative Array, same code on same level doesn't work

I have a really strange problem over here. Sorry for the ugly redundant parts, but it is only for prototyping. In both blocks I calculate the seconds of the given worktime. The first block was the first version and worked, but wasn't that robust. So…
heidelbeere
  • 157
  • 1
  • 12
2
votes
2 answers

Combine two arrays but add Values of duplicate keys together

I have two arrays, $ids and $quants (ids and quantities of stock items) that need to be combined, but instead of replacing or removing duplicates, their values should be added together. Currently I'm using array_combine() but this means that some…
hyclrs
  • 33
  • 7
2
votes
1 answer

Looping through array data

I have email template data and I'm trying to get it as associative array with keys and labels. But I can't make proper array as it should be. My template is the following: key_1:label1,key2:label2,... I get this text from database in this…
ivva
  • 2,819
  • 9
  • 31
  • 64
2
votes
2 answers

Sorting array of array php

I'm working on a little project based on codeigniter, I'm not a php developer and this is my problem: foreach ($checkeds['id_iscritti'] as $checked){ $iscritto = $this->pellegrinaggio_iscritti_m->get_iscritto($checked); …
2
votes
3 answers

Summarize object area with a Hash in Ruby

require 'sketchup' entities = Sketchup.active_model.entities summa = Hash.new for face in entities next unless face.kind_of? Sketchup::Face if (face.material) summa[face.material.display_name] += face.area end end I'm trying to get the…
Arto Uusikangas
  • 1,889
  • 5
  • 20
  • 33
2
votes
1 answer

Does passing objects as arguments represent an associative relationship?

What is the best way to enforce an associative relationship between these two classes? class ExcelFile def initialize(name) @name = name end end class Commodity attr_accessor( :xau ) def initialize(name) …
Zach Smith
  • 8,458
  • 13
  • 59
  • 133
2
votes
2 answers

Using an associative array to trap list of errors?

I am writing a procedure returning an IN OUT cursor. I want to check whether the IN parameters are appreciate. In case they are not, the cursor receive a grid of errors in the same place of results which only happen with appreciate parameters. The…
gngdoan
  • 21
  • 4
2
votes
1 answer

Whats the precedence and associativity of f x? Haskell

I know that . and $ both have right associativity, so that f . g . x would be f . (g . x) I also know that . has precedence over most, such that f . x + 5 * 4 would be f . ((x + 5) * 4) but when you have just f g x whats the associativity…
Arthur
  • 347
  • 1
  • 4
  • 14
2
votes
3 answers

How do you traverse and store XML in Blackberry Java app?

I'm having a problem accessing the contents of an XML document. My goal is this: Take an XML source and parse it into a fair equivalent of an associative array, then store it as a persistable object. the xml is pretty simple:
Greg
  • 23
  • 4
2
votes
1 answer

Hash::extract associated data

I have an Array that looks like: array( 0 => array ( "Something" => array( "id" => 1, "foo" => "bar" ), "User" => array( ... ) ), 1 => array ( "Something" => array( "id"…