This question already has an answer here: How can I access an array/object? 4 answers I'm trying to get the value of a given key if found using the array_key_exists function. $var = 35; if(array_key_exists($var, $_SESSION['cart_items'])) { //give the
I have to push an associative array in a normal array (not to convert). Example (NO CODE): project = {} element["title"] = "My title" element["description"] = "My description" is there a way to have this echo $proje
I'm reading som legacy code and come over a curious case: $my_assoc_array; /* User defined associative array */ $my_key; /* User defined String */ $value = $my_assoc_array["$my_key"]; Is there any clever reason why you would want to have citatio
This is my array: Array ( [0] => Array ( [price] => 106.060500 [unit] => 2.5900 ) [1] => Array ( [price] => 108.981500 [unit] => 2.1100 ) ) What I am trying to find is the lowest [price] value. To then return both the [price] and [unit]
i tried following code. it sometimes misses some key and value. Anybody can give idea why it is happening. $test= array(rand(0, 9)=>"a",rand(0, 9)=>"b",rand(0, 9)=>"c",rand(0, 9)=>"d",rand(0, 9)=>&quo
I've an array titled $all_events as follows : Array ( [status] => 1 [data] => Array ( [0] => Array ( [group_name] => [event_id] => 201 [view_id] => 0 [is_featured] => 0 [is_sponsor] => 0 ) [1] => Array ( [group_name] => [even
I have an associative array named map: var map = new Array(); map["exampleKey"] = 7; The keys are strings and the values are integers. Some keys may have the same value. I have tried solutions from similar questions like this one. However, I hav
I've an array titled $photos as follows: Array ( [0] => Array ( [fileURL] => https://www.filepicker.io/api/file/UYUkZVHERGufB0enRbJo [filename] => IMG_0004.JPG ) [1] => Array ( [fileURL] => https://www.filepicker.io/api/file/WZeQAR4zRJaPyW6
Is it possible to pass BASH associative arrays as argv to PHP scripts? I have a bash script, that collects some variables to a bash associative array like this. After that, I need to send it to PHP script: typeset -A DATA DATA[foo]=$(some_bash_functi
I have an array like this Array ( [0] => array('projectname', 'total_requests'),array('Project3' , 1), [1] => array('RTI' , 1), [2] => array('STAEP' , 3), [3] => ) I just want to remove [0]=>,[1]=>,[2]=>,[3]=> without converting th
I'm writing some kind of a function that accepts an associative array as an argument. This array can be: Empty Has only one element. With key either pageParam or wrapperClass. Has two elements. Must be keyed with pageParam and wrapperClass. Now i've
The problem: I cannot update an array in a while loop. An illustration (not the actual problem): declare -A wordcounts wordcounts["sentinel"]=1000 ls *.txt | while read f; do # assume that that loop runs multiple times wordcounts[$f]=$(wc -w $f)
Is there a way to get size of associative array in bash: declare -A array ...without iterating through the elements? The size of interest is both: just number of elements, and memory amount it consumes?${#array[@]} would return you the size of the ar
I am not asking you to write code for me. Any direction would be appreciated. I have an array in the following format: Array ( [0] => Array ( [title] => Here is the first title [count] => 765 [description] => Description ) [1] => Array ( [t
I'm trying to store some configuration variables in yaml represented as an associative array aka dictionary. Here is how I did: content_prices: - {country: AU, price: 6990000} - {country: AT, price: 4990000} - {country: BE, price: 4990000} This produ
I'm coming from the PHP world and I need to do do some tallying of records. In php I know this is simple, but how do I do the following in Groovy $logs = array( array( 'date' => '5-15', 'name' => 'foo' ...other stuff), array( 'date' => '5-15', 'n
I'm curious to know if there is some way to call a function using an associative array to declare the parameters. For instance if I have this function: function test($hello, $world) { echo $hello . $world; } Is there some way to call it doing somethi
I am attempting to generate a grouped array. Here is my code: function group_assoc($array, $key) { $return = array(); foreach($array as $v) { $return[$v[$key]][] = $v; } return $return; } Here is the current output: Array ( [2007] => Array ( [0] =>
I'm dynamically creating a 2 dimensional associative array (dictionary?) I'm trying to loop through its keys - while keeping one of the indexes constant, so for instance all of the values associated to "key" with 'john' in its first bracket: myh
I have an associate array that looks something like this: array ( 'device_1' => array('a','b','c','d'), 'device_2' => array('x','y','z') ) How can I implode the array into a standard array like this: array(0 => 'a', 1 => 'b', 2 => 'c', 3 =&
Hi everyone: I'm often running into the following issue with coffeescript and was wondering if anyone knows of a solution. Consider the following code: k=for x in [0...3] {foo:{bar:x,baz:3},qux:5} I have a lot of code that has this basic layout. Howe
In python I could do something like myMap = {key: [value1, value2]} and then access the value2 using myMap[key][1] Can I do something like this in javascript?Well, you can do this: var myMap = { key: [ value1, value2 ] }; var array = myMap.key; // or
I'm new to D programming language, just started reading The D Programming Language book. I run into error when trying one associative array example code #!/usr/bin/rdmd import std.stdio, std.string; void main() { uint[string] dict; foreach (line; std
I've accomplished the end goal for this already, but maybe there is a more elegant way of accomplishing this. If I have an array like such: $data = array( 'wood' => 2, 'metal' => 5, 'plastic' => 3, ); I want to get the top 2 key/value pairs from
I have this two arrays: $arr1=array( array("id" => 8, "name" => "test1"), array("id" => 4, "name" => "test2"), array("id" => 3, "name" => "test3")
Is there a php function that returns the sum of a row of an associative array? If not should I just use a counter and a foreach loop? Appreciate it!array_sum will work for you. $arr = array( 'key1' => 54.3, 65 => 10 ); $sum = array_sum($arr);
In manipulating data in Flash, which data format gives faster speeds in terms of searching and manipulation, XML or nested associative arrays? Meaning I currently send data in strings into the Flash client (I don't want to load an XML file) but I'm n
I have an array, i tried writing array_push($json['Request']['Header'], "key" => "val"); but i received an error. Writing the below works but it adds an array instead of just the key/val array_push($json['Request']['Header'], array(
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 do: $data['one'] and $data[0] to get the same
When declaring an associative array, how do you handle the indentation of the elements of the array? I've seen a number of different styles (PHP syntax, since that's what I've been in lately). This is a pretty picky and trivial thing, so move along i