arrays

Return array value as NSString

How can you return an array value (witch is a number) as a string? Current code: return [numbers objectAtIndex:row]; Have also tried: return @"%@", [numbers objectAtIndex:row]; With no luck.. Thanks :) PS: Yes, I am stupid. (: ...

remove a variable from a php session array

below is a php code that is used to add variables to a session. <?php session_start(); if(isset($_GET['name'])) { $name = isset($_SESSION['name']) ? $_SESSION['name'] : array(); $name[] = $_GET['name']; $_SESSION['name'] = $name; } if (isset($_POST['remove'])) { unset($_SESSION['name']); } ...

Does a type require a default constructor in order to declare an array of it?

I noticed that when you declare an array, the default constructor must be needed. Is that right? Is there any exception? For example, struct Foo{ Foo(int i ) {} }; int main () { Foo f[5]; return 0; } The code above does not compile. ...

How to dynamically create arguments for a method?

Being still somewhat new to Ruby, I'm not sure how to do this... Let's say I have a method that takes a variable number of arguments: def mytest(*args) puts args.to_json end Obviously I can call it with whatever I like, such as: mytest('one', 'two', 'three') No problem. But what I need to do is call it with a dynamically-created se...

Sort a collection of objects by number (highest first) then by letter (alphabetical)

I'm building a widget to show medal counts for the Olympics. I have a collection of "country" objects, where each has a "name" attribute, and "gold", "silver", "bronze" for medal counts. List should be sorted: 1. First by total medal count 2. If same medals, sub-sort by type (gold > silver > bronze, ie. two golds > 1 gold + 1 silver) 3....

C programming pointer arrays read file

The line *array[cnt] = thing causes a seg fault and I don't know why. Any ideas to fix this? long *Load_File(char *Filename, int *Size) { FILE *fp; if((fp = fopen(Filename,"r")) == NULL) { printf("Cannot open file.\n"); exit(-1); } fscanf(fp,"%d",Size); int cnt = 0; int items = *Size; l...

Illegal array-declaration in PHP ?

Why doesn't this validate with the W3C validator: 3 variables from form.html going into form.php: <?php $stuff1 = $_POST["stuff1"];//catch variables $stuff2 = $_POST["stuff2"]; $stuff3 = $_POST["stuff3"]; $myStuff[0] = $stuff1;//put into array $myStuff[1] = $stuff2; $myStuff[2] = $stuff3; ?> ...

Do you have to format the printout from print_r() in PHP to have it validate with W3C?

This will not validate because of the output from print_r, is it not supposed to be used "on a site" or do one have to format it in a certain way? <?php $stuff1 = $_POST["stuff1"];//catch variables $stuff2 = $_POST["stuff2"]; $stuff3 = $_POST["stuff3"]; $myStuff[0] = $stuff1;//put into array $myStuff[1] = $stuff2; ...

Comparing set of bits in byte array

Hello! I have a byte array, as follows: byte[] array = new byte[] { 0xAB, 0x7B, 0xF0, 0xEA, 0x04, 0x2E, 0xF3, 0xA9}; The task is to find the quantity of occurrences '0xA' in it. Could you advise what to do? The answer is 6. ...

How to declare array elements volatile in Java?

Is there a way to declare array elements volatile in Java? I.e. volatile int[] a = new int[10]; declares the array reference volatile, but the array elements (e.g. a[1]) are still not volatile. So I'm looking for something like volatile int[] a = new volatile int[10]; but it doesn't work that way. Is it possible at all? ...

PHP: How do I search in an unindexed array?

I have an array that is formatted like so (this example has 5 keys): [0]: HTTP/1.1 200 OK [1]: Date: Wed, 10 Feb 2010 12:16:24 GMT [2]: Server: Apache/2.2.3 (Red Hat) [3]: X-Powered-By: PHP/5.1.6 [4]: etc.. The array keys sometimes alternate, as one may be omitted. How can I search for the array with "Server: ..." in it, and if it exi...

Is there any way to specify a generic argument to a function with the restriction that it should implement a given interface

Example: I have a function that works with vectors: double interpolate2d(const vector<double> & xvals, const vector<double> & yvals, double xv, double yv, const vector<vector<double> > &fvals) { int xhi, xlo, yhi, ylo; double xphi, yphi; bracketval(xvals,xv,xhi,xlo,xphi); bracketval(yvals,yv,yhi,ylo,yphi); return (f...

Trying to find if array is full or not

I'm working with JQuery to determine if an array, built earlier, with a determined number of indexes, is full or not. When created, array looks like this : ,,,,,, All I want to do is find if every position is filled or not. So bascially, i'm trying to test if and only if [x,x,x,x,x,x] For example, if [x,x,x,,x,x] or if [x,,,,,] ...

Retrieving specific hash key values from an array of hashes

All, I was wondering if anyone knew a better patten than: array_of_hashes.map { |hash_from_array| hash_from_array[:key] } for retrieving an array of values with a specific key from an array of hashes containing that key. ...

porting this php code to c#

I'm having trouble porting this code below to c#. my main trouble is with the $fb_activity_array. $fb_activity_message = '{*actor*} played this game'; $fb_activity_array = json_encode(array('message' => $fb_activity_message, 'action_link' => array('text' => 'Play Now','href' => 'http://yoururltoplaygamegere'))...

Checkboxlist to String, Save to Database, Then convert to Array

Hi there. I know the subject might be a little strange, but I wasn't sure how to exactly describe my goal I'm trying to do some Role based permissions in a content management system. The best way I can think of to do this is to pull the list of roles from the database and place them in a CheckBoxList. From there, I save a comma separ...

PHP - how to access this data structure?

Hi, This is a newbie question - how do I access the value0, value1, ... entities? object(SimpleXMLElement)#43 (2) { ["@attributes"]=> array(3) { ["ABC"]=> string(1) "1" ["DEF"]=> string(14) "recordXYZ" ["GHI"]=> string(1...

Initializing a Char*[]

Question is in the title, how do I initialize a char*[] and give values to it in C++, thank you. ...

Use Sort Whilst Still Retaining Keys

When I use the sort function in php it deletes all of the keys. What's an alternative method? ...

Oracle SP array parameter in php

I'm calling an Oracle Stored procedure which takes an array as an input parameter. Owa.vc_arr(varchar2) I'm making a call in php and getting an error. Any help would be greatly appreciated. Code which i'm using is given below. function findSupplier($ptype) { $proCall = 'BEGIN ICPISSAAPILIB.FIND_SUPPLIER(:P_PRODUCT_TY, :P_RESULTS); E...