arrays

delphi 7 Items property

I come from Java background, where we have data structures with interfaces that if its collection it support certain behaviour, and a set has another. while programming in Delphi I thed to hit a brick wall when it comes in asking the reflection about the behaviour of items, its very strange. for example this code does not compile ...

object strorage capacity Array list

What are the consequences if we store huge objects collection in Arraylist when it is not expecting them (i.e we may initialized the Arraylist to accommodate 10/100/1000 objects, however at runtime we might store some 100 thousand objects). and which is better out of below two in case we know this will happen at some point of time. 1).T...

Elegant way to sort an array like this

This is my array: $arr = array(-3, -4, 1, -1, 2, 4, -2, 3); I want to sort it like this: 1 2 3 4 -1 -2 -3 -4 So first there would be values greated than zero sorted from the lowest value to the highest value, then there would be negative values sorted from the highest value to the lowest value. Is there some elegant way to do this...

array_key_exists in a foreach

Hi There I am running this code currently, <?php foreach($search_results as $rslt) : ?> <? $code = $rslt['code']; if(array_key_exists($code, $short_list)) { $set = "set"; } ?> <div class="row <? echo $set;?>"></div> What I am trying to achieve is that if the array equals the $rslt['code'] then give the...

PHP - Merge and group array data

How to group this: Array( [0] => Array( [brand] => 'ABC', [model] => 'xyz', [size] => 13 ) [1] => Array( [brand] => 'QWE', [model] => 'poi', [size] => 23 ) [2] => Array( [brand] => '...

Powershell: call an exe with parameters from items in an array?

I have a set of commands that I'd like to run and do some returncode checks against the result, so i figured it would be easy to put them into an array for execution. Let's take this one as an example: C:\windows\system32\inetsrv\AppCmd.exe set config "Default Web Site/" /section system.webServer/webdav/authoring /enabled:true /commit:...

Differentiate associated array from regular array

Without having to change the function signature, I'd like a PHP function to behave differently if given an associated array instead of a regular array. Note: You can assume arrays are homogenous. E.g., array(1,2,"foo" => "bar") is not accepted and can be ignored. function my_func(Array $foo){ if (…) { echo "Found associated array...

Javascript / jQuery Populating Multidimensional Arrays... Array with array elements

I'm trying to populate a multidimensional array (array with array elements) via Javascript or jQuery... push() is probably the wrong method to use, but I've tried a couple of others and I can't seem to get beyond single dimensional arrays. Here's the latest try so far - any advice or snippets on how I might be able to populate arrays per...

javascript - sort by the order of a second array

Given: var a1 = [{name:'Scott'}, {name:'John'}, {name:'Albert'}]; var sortOrder = ['John', 'Scott', 'Albert']; How can I sort the first array (by property) based on the order specified in the second array. // result: [{name:'John'}, {name:'Scott'}, {name:'Albert'}] Thanks. ...

NSMutableArray getting overwritten on every pass within a loop

greetings Cocoa masters - this simple issue has me crawling the walls. I have a custom class called Movie which consists of a bunch of properties and a few collections. I am populating it successfully using FMDB and SQLite. However, with each pass through the result collection from the DB, my addObject: seems to be writing over the entir...

C++ pointer to array of pointers to function pointers? any clue how to do it?

Maybe is a silly questiion, but I haven't found a solution to what I want. Basically, I would like to declare a pointer to an array of pointers to function pointers to functions with N parameters that returns an const pointer to an int. The code below is declaring an array of pointers to the function pointers: int *const (**fptr[10])...

c++ return array in a function

Hi before someone storm "it's simple or duplicate" i swear i've searched but because it's pretty easy i couldn't find it between much more complex ones , unlucky maybe. Anyway my question is very simple , I have normal array int arr[5] that is passed to function fillarr(int arr[]) all i want is fixing the next code: int fillarr(int arr[...

Best way to convert string to array of object in javascript?

Hi guys, I want to convert below string to an array in javascript. {a:12, b:c, foo:bar} How do I convert this string into array of objects? Any cool idea? ...

Negative array indexes in C?

I was just reading some code and found that the person was using arr[-2] to access the 2nd element before the arr, like so: |a|b|c|d|e|f|g| ^------------ arr[0] ^---------- arr[1] ^---------------- arr[-2] Is that allowed? I know that arr[x] is the same as *(arr + x). So arr[-2] is *(arr - 2), which seems ok. What ...

JAVA - Problems initializing individiual elements of an array.

Hello there. I'm very new to programming and I must be missing something here. The first section works. The second section blows up with an error. Why is that? // this works private static int[] test2 = {1,2,3}; // this is ok private static int[] test1 = new int[3]; // these three lines do not work // tooltip states ... "cannot fin...

Does initialized java array go onto stack or heap?

void someMethod() { byte[] array = { 0, 0 }; } Will this array be stored in heap or on the stack? ...

How to get all the possible values of a function called with any two values of an array?

Consider this code: class MyClass { string PropertyA; int PropertyB; double PropertyC; object PropertyD; static ComparisonResult Compare(MyClass a, MyClass b){ // returns a ComparisonResult with // _sampleElement = a // _commonProperties = flags that describe the common properties of a and b ...

Writing an array as a comma separated list to screen

Now it seems like a really simple question and I may just be being thick, but what I'm trying to achieve is basically print an array to screen in the following format: Item 1, Item 2, Item 3, Item 4 Although I say to screen, as that was the best way I could describe it, I'm actually writing it to the page inside some Javascript. The w...

Arrays: Defined in .NET, Applied in VBA

I have created a VB.NET 2008 Class Library that has, for the most part, been working quite well with VBA. I can perform most of the functionality that is required but I have recently run into a pretty severe problem. The reason we are working with both programming interfaces is because we need to be able to do "on the fly" coding and th...

Algorithm to get changes between two arrays

I needed to create an algorithm which will (efficiently) take an old array and a new array and give me back the changes between the two (which items added, which removed). It happens to need to be in JavaScript (to run in the browser) but the algorithm's more important than the language. This is what I came up with: http://jsbin.com/ose...