arrays

Any way to define getters for lazy variables in Javascript arrays?

I'm trying to add elements to an array that are lazy-evaluated. This means that the value for them will not be calculated or known until they are accessed. This is like a previous question I asked but for objects. What I ended up doing for objects was Object.prototype.lazy = function(var_name, value_function) { this.__defineGetter__(...

php multi-dimensional array manipulation: replace index by one of its values

I would like to make this multidimensional array more readable by using one of its sub key values as index. So this array: array( [0]=>array('group_id'=>'2','group_name'=>'red','members'=>array()), [1]=>array('group_id'=>'3','group_name'=>'green','members'=>array()), [2]=>array('group_id'=>'4','group_name'=>'blue','members'=>array()), ...

Fast and efficient way to read a space separated file of numbers into an array?

I need a fast and efficient method to read a space separated file with numbers into an array. The files are formatted this way: 4 6 1 2 3 4 5 6 2 5 4 3 21111 101 3 5 6234 1 2 3 4 2 33434 4 5 6 The first row is the dimension of the array [rows columns]. The lines following contain the array data. The data may also be formatted with...

declare or convert a string to array format PHP

How to convert a string format into an array format? I have a string, $string = 'abcde' I want to convert it to a 1 element array $string[0] = 'abcde' Is there a built in function for this task? Or the shortest way is to $string = 'abcde'; $array[0] = $string; $string = $array; TIA ...

PHP: Collect all variables passed to a function as array?

Hi everybody, I was thinking about the possibility of accessing all the variables that are passed into an function, and merge them into an array. (Without passing variables into an array from the beginning) Pseudo-code: // Call function newFunction('one', 'two', 'three' ) ;// All values are interpreted as a one rray in some way // Fu...

What is the last entry in an unfilled array (C++)?

I put C++ because I'm just starting in C# and I'm not sure if there's a difference. if you declare an array char arr[10] and fill in values for arr[0] through arr[8], what value will be put in arr[9]? a space ' '? An endline '\n'? '\0'? Or is it nothing at all? I'm asking this because I've always used tactics like this char word...

Help with a sort method

Hi there, If i have an array of strings for example Static final String[] TEST = new String[] { "g","a","b","t","e" }; How would i go about sorting this in alphabetical order please? ...

When should I use indexed arrays of OpenGL vertices?

I'm trying to get a clear idea of when I should be using indexed arrays of OpenGL vertices, drawn with gl[Multi]DrawElements and the like, versus when I should simply use contiguous arrays of vertices, drawn with gl[Multi]DrawArrays. (Update: The consensus in the replies I got is that one should always be using indexed vertices.) I hav...

Java & android: Help linking an item in a listView to its correct view, but not the way i know of.

Hi, i'm developing an android app, and what i have is a String array of restaurants in one class... static final String[] AtoZ = new String[] { "Ananda", "Brambles Cafe", "Brannigans", "Buona Sera", "Cafe Mao", "Cafe Mimo", "Dante", "Eddie Rockets", "Frango's World Cuisine", "Nando's", "Overends Restaura...

one line assert to test if STL container is sorted

Is there a way to write a one line condition that would return true if STL container is sorted? The container in question is std::vector I intend to use it in an assert ...

java applet - array checking

OK so my code is here: http://www.so.pastebin.com/m7V8rQ2n What I want to know... let's say I have an image which I can redraw on tiles... is there a way to check for future tiles so I DON'T go out of bounds of my already defined tile map? Like if I were at the edge of a map... it would NOT let me go past it? Thanks. ...

Get array from enter seperated values

I have a TextArea with enter seperated values: For Example: Value1 Value2 Value3 Value4 Value5 Is there a fast way to put them in a String array String[] newStringArray = ??? ...

adding up value of array and getting the average

I have an array that looks similar to this, [4] => Common_Model Object ( [id] => 4 [name] => [date_created] => [last_updated] => [user_id_updated] => [_table] => [_aliases] => Array ( [id] => 4 [name] => [date_c...

C++; Using an array of derived objects as an array of base objects when the sizes are the same (CComVariant/VARIANT)

I'm using code that treats an array of derived objects as an array of base objects. The size of both objects is the same. I'm wondering: Is this safe in practice, bearing in mind that the code will only ever be compiled on Microsoft compilers? Here's my example: BOOST_STATIC_ASSERT(sizeof(VARIANT)==sizeof(CComVariant)); //auto_arra...

Comparing arrays with sql

I want to perform a 'SELECT' statement with a byte array (binary) parameter as a condition. I tried to google it, but didn't find anything useful. In general, I keep information of files in the database. one of the properties is the file's hash (binary). I want to give a hash to the SELECT statement, and get all rows with the same hash...

Storing values of an array in one variable

Hello, I am trying to use md5 code to calculate checksums of file. Now the given function prints out the (previously calculated) checksum on screen, but I want to store it in a variable, to be able to compare it later on. I guess the main problem is that I want to store the content of an array in one variable. How can I manage that? ...

PHP Associative array sort

I have an array like one below. Currently it is sorted alphabetically by the OwnerNickName field. Now i want to brig the array entry with OwnerNickName 'My House' as the first entry of the array and rest sorted alphabetically by OwnerNickName. Any idea? Array ( [0318B69D-5DEB-11DF-9D7E-0026B9481364] => Array ( [O...

c# wrapper for a c DLL

I'm attempting to write a wrapper so that my C# application can use a DLL written in C. Here is a method defintion that i'm trying to wrap: void methodA(const uint32_t *data); //c header declaration The issue I'm having is trying to figure out how to give a equivalent pointer from c#. In c# I want it to operate on a: UInt32 data[] ...

Question : Perl map - need to map a array into a hash as arrayelement->array_index

Hi folks. I have a array like this: my @arr = ("Field3","Field1","Field2","Field5","Field4"); Now i use map like below , where /DOSOMETHING/ is the answer am seeking. my %hash = map {$_ => **/DOSOMETHING/** } @arr Now I require the hash to look like below: Field3 => 0 Field1 => 1 Field2 => 2 Field5 => 3 Field4 => 4 Any help? ...

Protecting from crashes (beyond bounds) with [object objectAtIndex:]

Hi! I'd like to know if there's a way to verify if an index exists before getting it. So it'd be way to protect my code against: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (2) beyond bounds (0)' Like in PHP you can do: isset($object[10]); and it'll return true if...