associative-array

C# equivalent to php associative array

僤鯓⒐⒋嵵緔 提交于 2019-11-26 21:50:18
问题 I'm customizing a shopping cart application in php. In this application, I have to integrate some parts with another C#.net application, so I'm using a webservice in a php shopping cart. In one method of the webservice, some values should pass as an associative array like this: $proxy = new SoapClient('www.mywebservice.com?wsdl'); $associative_array= array( 'abc'=> 1,'def'=>0,'ghi'=>1,'jkl'=>0 ); $proxy->call($sessionId, 'methodname', array('somevalue', $associative_array)); In php its

Iterating over a complex Associative Array in PHP

眉间皱痕 提交于 2019-11-26 20:22:23
Is there an easy way to iterate over an associative array of this structure in PHP: The array $searches has a numbered index, with between 4 and 5 associative parts. So I not only need to iterate over $searches[0] through $searches[n] , but also $searches[0]["part0"] through $searches[n]["partn"] . The hard part is that different indexes have different numbers of parts (some might be missing one or two). Thoughts on doing this in a way that's nice, neat, and understandable? Nest two foreach loops : foreach ($array as $i => $values) { print "$i {\n"; foreach ($values as $key => $value) { print

How to use PHP in_array with associative array?

萝らか妹 提交于 2019-11-26 20:15:38
问题 Is there any php function such as in_array for associative arrays you get by the mysql function "mysql_fetch assoc" ? For example, if I have an $array that looks like this: array(0=>(array(ID=>1, name=>"Smith"), 1=>(array(ID=>2, name=>"John")) Can I do something like in_array(key,value,array)? Or in my case, if I am looking for the ID value of "1", in_array("ID",1,$array) . This is my solution, comment on it if you think it's the right way: function in_assoc_array($key,$value,$array) { if

Hash Table/Associative Array in VBA

不羁岁月 提交于 2019-11-26 18:51:15
I can't seem to find the documentation explaining how to create a hash table or associative array in VBA. Is it even possible? Can you link to an article or better yet post the code? I think you are looking for the Dictionary object, found in the Microsoft Scripting Runtime library. (Add a reference to your project from the Tools...References menu in the VBE.) It pretty much works with any simple value that can fit in a variant (Keys can't be arrays, and trying to make them objects doesn't make much sense. See comment from @Nile below.): Dim d As dictionary Set d = New dictionary d("x") = 42 d

Finding the minimum value's key in an associative array

霸气de小男生 提交于 2019-11-26 17:44:38
问题 In PHP, say that you have an associative array like this: $pets = array( "cats" => 1, "dogs" => 2, "fish" => 3 ); How would I find the key with the lowest value? Here, I'd be looking for cats . Is there some built in PHP function that I've missed which does this? It would also be great if there was a solution that accounted for several values being identical, as below: $pets = array( "cats" => 1, "dogs" => 1, "fish" => 2 ); Above, I wouldn't mind if it just output either; cats or dogs .

Display array values in PHP

梦想与她 提交于 2019-11-26 17:43:27
问题 So, I'm working with PHP for the first time and I am trying to retrieve and display the values of an array. After a lot of googling, the only methods I can find for this are print_r , var_dump or var_export . However, all of these methods return something that looks like this: [a] => apple [b] => banana [c] => orange I can't figure out how to style this outout. I need to strip away the [a] => part and add commas. I know this must be a pretty straightforward process but I haven't been able to

Associative array, sum values of the same key

只愿长相守 提交于 2019-11-26 17:26:45
问题 So I have this associative array (dump done with kint) d Instead of having the key " Conference " repeating 3 times. I want to have it just once and sum the 3 values into one in order to have something like: Conference : 4534 And same thing for all other keys that are repeating.. Is there a native function that can do that ? 回答1: You can try $data = array( 0 => array( 'event' => 'Conference', 'budget' => 3700, ), 1 => array( 'event' => 'Conference', 'budget' => 500, ), 2 => array( 'event' =>

PHP - Merge two arrays (same-length) into one associative?

半世苍凉 提交于 2019-11-26 17:22:27
问题 pretty straightforward question actually.. is it possible in PHP to combine two separate arrays of the same length to one associative array where the values of the first array are used as keys in the associative array? I could ofcourse do this, but I'm looking for another (built-in) function, or more efficient solution..? function Combine($array1, $array2) { if(count($array1) == count($array2)) { $assArray = array(); for($i=0;$i<count($array1);$i++) { $assArray[$array1[$i]] = $array2[$i]; }

How does PHP index associative arrays?

为君一笑 提交于 2019-11-26 17:13:54
问题 As I know, in associative arrays , if the keys is not set, it will be set automatically. But it seem doesn't make sense in this case: $a = array( '1' => 'One', '3', '2' => 'Two'); print_r($a); Outputs: Array ( [1] => One [2] => Two ) So where is the '3'? 回答1: Within your user defined array you are assigning the keys manually your array means as array(1 => 'One',3, 2 => 'Two');//[1] => One [2] => 3 [2] => Two Here we have two identical index and as per DOCS its mentioned that the last

Associative arrays in Shell scripts

时间秒杀一切 提交于 2019-11-26 16:56:22
We required a script that simulates Associative arrays or Map like data structure for Shell Scripting, any body? Jerry Penner To add to Irfan's answer , here is a shorter and faster version of get() since it requires no iteration over the map contents: get() { mapName=$1; key=$2 map=${!mapName} value="$(echo $map |sed -e "s/.*--${key}=\([^ ]*\).*/\1/" -e 's/:SP:/ /g' )" } Another option, if portability is not your main concern, is to use associative arrays that are built in to the shell. This should work in bash 4.0 (available now on most major distros, though not on OS X unless you install it