arrays

Array Slice in C#

I'm looking to slice a two dimensional array in C#. I have double[2,2] prices and want to retrieve the second row of this array. I've tried prices[1,], but I have a feeling it might be something else. Thanks in advance. ...

How can I use an array as a hash value in Perl?

Ok, so here's the entire structure I'm trying to create. I need to create an anonymous array that I can use as a hash value. This works in my program: $result = { count, 2, elementList, [ {name => "John Doe", age => 23}, {name => "Jane Doe", age => 24} ] }; I'm trying to create the exact same thing with cod...

Putting user input into char array (C Programming)

I need to read the input from the console and put it into an array of chars. I wrote the following code, but I get the following error: "Segmentation Fault" #include <stdio.h> #include <stdlib.h> int main() { char c; int count; char arr[50]; c = getchar(); count = 0; while(c != EOF){ arr[count] = c; ...

How to quickly zero out an array?

I am currently doing it in a for loop, and I know in C there is the ZeroMemory API, however that doesn't seem to be available in C#. Nor does the somewhat equivalent Array.fill from Java exist either. I am just wondering if there is an easier/faster way? ...

C Programming. Reading input and parsing it into words

Hi, I'm writing a small program in C that will read input from the console. Then put it into a char array. After that I need to split the array into words. I'm not sure how to do this. So far I have put the input into a char array. I need to know if there is a way to tokenize based on a blank character. Or any other suggestions on how ...

numpy array slice using None

This had me scratching my head for a while. I was unintentionally slicing an array with None and getting something other than an error (I expected an error). Instead, it returns an array with an extra dimension. >>> import numpy >>> a = numpy.arange(4).reshape(2,2) >>> a array([[0, 1], [2, 3]]) >>> a[None] array([[[0, 1], ...

Array.filter to dynamically test values

Hi, this is from Adobe docs: package { import flash.display.Sprite; public class Array_filter extends Sprite { public function Array_filter() { var employees:Array = new Array(); employees.push({name:"Employee 1", manager:false}); employees.push({name:"Employee 2", manager:true}); ...

refactoring Java arrays and primitives (double[][]) to Collections and Generics (List<List<Double>>)

I have been refactoring throwaway code which I wrote some years ago in a FORTRAN-like style. Most of the code is now much more organized and readable. However the heart of the algorithm (which is performance-critical) uses 1- and 2-dimensional Java arrays and is typified by: for (int j = 1; j < len[1]+1; j++) { int jj = (con...

how to store an array in the controller and use in the view file in cakephp

In my Users controller, I find the number of forms that the user has created by querying the 'Forms' table and store it in an array. But how to use the array variables in the view file. Normally, I would set the variable in the controller using set function and use it in the view file as such. But how to set an array in the controller? ...

PHP Array & for each

Hi, I'm using a multi dimensional array in php, I would like to know how to get the "field name" of the value I'm returning in my foreach loop. $_SESSION['filter']['dateCreation'] = 'ASC'; $_SESSION['filter']['client'] = 'test'; print_r($_SESSION['filter']); foreach ($_SESSION['filter'] as $filter) { // how do I echo the name of t...

How do you replicate an array whilst keeping the same keys?

Ok. I've written a simple(ish) function to take an argument and return the same argument with the danger html characters replaced with their character entities. The function can take as an argument either a string, an array or a 2D array - 3d arrays or more are not supported. The function is as follows: public function html_safe($inp...

Polymorphism & Pointers to arrays

Hi all, I have a class A: class A { public: virtual double getValue() = 0; } And a class B: class B : public A { public: virtual double getValue() { return 0.0; } } And then in main() I do: A * var; var = new B[100]; std::cout << var[0].getValue(); //This works fine std::cout << var[1].getValue(); //This, ...

Merging and array by value instead of key in PHP

I have two arrays of values that I would like to combine - but the only methods that PHP provides seem to combine by key instead of value. Here is a hack that I was able to use to get this to work, but I am wondering if there is a better method or a native function that I have missed. It's been a while since I last used arrays and it see...

Is passing multiple sets of arguments as an array in JavaScript faster than multiple function calls?

After becoming slightly uncomfortable with multiple calls to the same function, with different parameters (as shown in the dom ready section of the code below), I decided to test out passing the parameters for this function by iterating through an array instead (as shown in mouse_function_two). To my surprise I found that mouse_function_...

How to combine the keys and values of an array in PHP

Say I have an array of key/value pairs in PHP: array( 'foo' => 'bar', 'baz' => 'qux' ); What's the simplest way to transform this to an array that looks like the following? array( 'foo=bar', 'baz=qux' ); i.e. array( 0 => 'foo=bar', 1 => 'baz=qux'); In perl, I'd do something like map { "$_=$hash{$_}" } keys %hash Is there some...

Consolidate an array in PHP?

I have an array that looks like the following: Array ( [0] => Array ( [id] => 10 [value] => 5 ) [1] => Array ( [id] => 10 [value] => 1 ) [2] => Array ( [id] => 11 [value] => 1 ) [3] => Array ( [id] => 11 [value] => 1 ) ) How ca...

initial value of int array in C

When declaring an array in C like this: int array[10]; What is the initial value of the integers?? I'm getting different results with different compilers and I want to know if it has something to do with the compiler, or the OS. ...

Passing Array using GET with PHP/jQuery

Hello, I'm currently using $.getJSON to pass an array of ids. It basically constructs a URL like this: http://domain.com/json.php?id=1&amp;id=2&amp;id=4 My question is: How can I take these ids that are passed (1,2,4) and place them in my where clause? Something like: $id = $_GET['id']; $sql = SELECT * FROM table WHERE usrID ...

Initializing a string array in a method call as a parameter in C#

If I have a method like this: public void DoSomething(int Count, string[] Lines) { //Do stuff here... } Why can't I call it like this? DoSomething(10, {"One", "Two", "Three"}); What would be the correct (but hopefully not the long way)? ...

$getJSON not being recognized as an array

Hello, I'm trying to use jQuery's $getJSON to send an array of 'ids'. Here's what my jQuery looks like: var calendarIds = []; $("#jammer :selected").each(function(i, selected){ calendarIds[i] = $(selected).val(); }); $.getJSON("test.php", { start: start.getTime() / 1000, end: end.getTime() / 1000, calendarid:...