arrays

taking tally of values in array

I have an array: $record = array(Won,Lost,Won,Won,Lost); I want to count the number of wins and losses in the array. So everytime it finds "Won" in the array, do a $won++, and the same for loss, $loss++ I want to print out the record after that is completed. print $won.' - '.$lost; I think I figured it out, revisions to make this...

Receive arrays of arrays of ... in D function?

Don't know if is possible, I want receive maybe data[n] or data[n][n][n]. In C could be (correct me if wrong): void save_data(void* arr, int n, int dimensions) { // do ugly things } But must exist a more elegant way in D. ...

How is it that find_by_id, etc. work on an ActiveRecord array?

Forgive me if I've got my terminology wrong; I am still quite new to Ruby and Rails. For school I am working on an RoR project as part of a team. I was pair programming with a teammate, who actually happens to be experienced in RoR; and I wrote something like the following: d = self.deliverables.find_all_by_lifecycle_id(self.lifecycle_...

Java Array RGB Manipulation

Ok so lets say I have an int[][] arrayA and an int[][] arrayB. At any given coordinate in this array lies an RGB value. What I want to do is merge the RGB values from arrayA and array2 into a new array, newArray, using a weighted average method. So what I'm doing is extracting the red, green, and blue values from each RGB value like th...

How to create a Static NSMutableArray in a class in Objective c?

I have Class A which is super class for both class B and class C. I need to store the objects of Class A in 'static' NSMutablearray defined in Class A. Is it possible to modify data stored in MSMutableArray using methods in Class B and Class C? How to create and initialize Static array? An example would be of more help. thanks in advance...

Sorting an array with uksort()

Hello! I have an array like this one: $a = array("MA1" => 0, "MA10" => 1, "MA20" => 2, "MA5" => 3, "SM10" => 4, "SM8" => 5, "SM20" => 6, "SN33" => 7); I want to sort it, that I will have the following order: $a = array("MA1" => 0, "MA5" => 3, "MA10" => 1, "MA20" => 2, "SM8" => 5, "SM10" => 4, "SM20" => 6, "SN33" => 7); So I need a...

search in php multidimensional array

Hi, I would like to find presents of value in a two-dimensional array according to its key(index).Is there any solution in php? Consider my array is as follows Array ( [0] => Array ( [id] => 3 [value] => tom ) [1] => Array ( [id] => 4 [value] => john ) ) How can I find john is present in above array.Already tried it by i...

What is the correct way to offset a pointer?

I want to pass a pointer to a function. I want this pointer to point to some place in the middle of an array. Say I have an array like such unsigned char BufferData[5000];, would the following statement be correct syntactically? writeSECTOR( destAddress, (char *)( BufferData + (int)(i * 512 )) ); // destAddress is of type unsigned long...

How to echo certain number of elements from PHP Array

Hello, If I have an array with say 100 elements.. how can I echo/show the top 5 only for example? Thank you :) ...

I need an array_keys_recursive()

$temp = array(); function show_keys($ar) { foreach ($ar as $k => $v ) { $temp[] = $k; if (is_array($ar[$k])) { show_keys ($ar[$k]); } } return $temp; } I tried using that function but it still only returns the first key. ...

filling a drop-down box from an array

I am kinda new to this, but I am trying to fill an array from a sql statement that pulls several permit numbers from a table. So in the table every person can have multiple permits, I need to store all the permit numbers and display them in a drop down box via javascript. I get the information from the array but the information is disp...

Numpy - why value error for NaN when trying to delete rows

Hi, I have a numpy array: A = array([['id1', '1', '2', 'NaN'], ['id2', '2', '0', 'NaN']]) I also have a list: li = ['id1', 'id3', 'id6'] I wish to iterate over the array and the list and where the first element in each row of the array is not in the list, then delete that entire row from the array. My code to date: fr...

How can I retrieve data from an array, 3 at a time?

Is there a better way in PHP to access this array in groups of three? Let's say my array is a comma separated string like : ("Thora","Birch","Herself","Franklin Delano","Roosevelt","Himself (archive footage)","Martin Luther","King","Himself (archive footage) (uncredited)") although the array can end up being much larger, each one wil...

I need C++ array class template, which is fixed-size, stack-based and doesn't require default constructor

So, I've been looking at boost::array but it does require default constructor defined. I think the best way of filling this array with data, would be through a push_back(const T&) method. Calling it more times than SIZE (known at compile-time) would result in assert or exception, depending on build configuration. This way it would always...

int[] type and documentation

Hi, I'm puzzled about arrays in C#. I can't find any documentation on MSDN about for example the object double[]. I do find documentation about int, array, collections, ... but can't find out of what type double[] is. If I do double[] a = new double[10]; a.GetType(), I find that the type of a is System.Double[] I believe that the type ...

PHP: foreach and array issue

I have this: foreach($_POST as $key => $value) { $data[$key] = filter($value); } filter(); strips if any tags, and real escape them. Now I have an array in the POST form too, so I am getting errors in strip_tags() and mysql_real_escape_string. How should I let only $_POST["Searching"] not get filtered by filter(); ? ...

How to Deserialize xml with muliple matching nodes to array in c#

Hi, I want to deserialise an xml document with a number of same name nodes into an IList in c# I do not have control over the xml and therefore cant change it. <root> <node1 name="" version="" /> <node1 name="" version="" /> <node1 name="" version="" /> <node1 name="" version="" /> <node2></node2> <node3></node3> </root> I have...

Identical strings comparison gives me false

I have two identical strings, one in an array and one in a String variable. When I compare these IDENTICAL strings I get false every time. I have debugged and debugged, but I get the same result every time. Here is the code in question String temp = ""+(num1*num2); Boolean equal = temp == answers[i]; if(equal) { correct[i] = true; ...

How to Dynamically assign request id to any array in PHP. e.g. $_SESSION[] or a simple array?

Hi friends I am stuck with a program logic in array. Basically, what am trying to do is that I have link that says "Unlock answer" use clicks on this link and then I get the request id and unlock the specific answer. But I have other answers there which needs to be unlocked. And user again and again clicks on any answer to unlock. But am...

lookup table in c

Hi, I'm creating a lookup table in C When I define this: typedef struct { char* action; char* message; } lookuptab; lookuptab tab[] = { {"aa","bb"}, {"cc","dd"} }; it compiles without errors but when I do something like this: typedef struct { char* action; char* message[]; } lookuptab; lookuptab tab[] = { {"aaa", {"bbbb"...