An associative array is an abstract data type composed of a collection of unique keys mapped to a collection of values.

learn more… | top users | synonyms

1
vote
1answer
36 views

Why can't I reference keys in the result of this PHP function? [duplicate]

Why does this code fail function f(){ return array('k'=>'abc'); } print_r(f()['k']); and this code work? function f(){ return array('k'=>'abc'); } $a = f(); print_r($a['k']); The ...
1
vote
6answers
33 views

Insert a element from php variable in associative array

I have a conditional string like this: echo $cnd = "'use_funds'=>'no'"; And my $data array is : $data = array( $cnd, 'quantity' => $_POST['qty_' . $q], 'veg_name' => ...
0
votes
4answers
37 views

In PHP, filter an Array of Associative Arrays

In PHP, are there any inbuilt functions to turn [{"id":1, "name":"John"}, {"id":2, "name":"Tim"}] into [{"id":1}, {"id":2}] ? I've used JSON to describe the objects above, but that's just a ...
0
votes
1answer
21 views

Merging two arrays then sorting them

Beginner here. I have two arrays, one that contains my values($m1) and the other contains what I want to use as keys($pn) (non unique strings). They have the same length (465) and $pn[0] is the key ...
0
votes
2answers
26 views

Ordered Map / Hash Table in R

While working with lists i've noticed an issue that i didn't expect. result5 <- vector("list",length(queryResults[[1]])) for(i in 1:length(queryResults[[1]])){ id <- queryResults[[1]][i] ...
0
votes
3answers
36 views

Creating an associative array with strings

I read some words from a text file, storing each word as an array element using the file() function. Now I need to sort each word and create an associative array that stores the sorted strings as keys ...
0
votes
2answers
19 views

custom validation class only testing last element

I have been trying to make a custom validation class, but it is bothering me that it only is test thing last element it sees. I need it to test everything I put into it. <?php class Valid { ...
0
votes
1answer
24 views

Trace hierarchical tree for JSON array

I just can't understand why I get undefined index for 'post' in the foreach. Here's the function I use to authenticate to the API via cURL, grab the JSON, cache it and extrapolate with the foreach the ...
0
votes
2answers
25 views

calling values from JSON associative array in JQUERY

I'm attempting to call values from a JSON associative array. I'm finding difficulties as my object is wrapped in "[ ]". For instance: var scifi = [ { "Show":"TNG", ...
0
votes
1answer
15 views

PHP: Find dynamic element from nested associated array

I'm working on a function that looks like this: public function myfunction($mainArr, $keys) { // $mainArr: a nested associative array // $keys: a simple array of strings, example: ...
-7
votes
1answer
46 views

Associative array

I have two arrays: arr1([0]=>1400.20 [1]=>1630.32 [2]=>2531.30 [3]=>9845.62) arr2([0]=>150 [1]=>134 [2]=>901 [3]=>631) and I have ...
0
votes
1answer
31 views

PHP: pushing new data (including new key) in associative array

So I am trying to push new data into an array. This data inlcudes new key values. This is what I am using now, however this will always overwrite the last with the newer in stead of adding a row to ...
0
votes
2answers
20 views

using php class object like associative array [duplicate]

so i'm having this class: class c_user { function __construct($userID) { dbOpen($db); // open database $sq = "select * from users where user_id='".$userID."'"; $rs = ...
-2
votes
1answer
40 views

Storing true or false into an associative array

I've compiled a list of 'old browsers'. I'm doing a check on each one to see if they are in the HTTP_USER_AGENT. My results keep storing as true in the array even when they're false. My problem ...
1
vote
3answers
37 views

Failed to print what is stored in Iterator

// unordered_map::find #include <iostream> #include <string> #include <unordered_map> using namespace std; int main () { std::unordered_map<std::string,double> mymap; ...

1 2 3 4 5 56
15 30 50 per page