arrays

Can I use Perl's map with an array slice?

I'm just trying to shorten a line of code that assigns HTML::Element->as_trimmed_text from an array of HTML::Elements to some variables - pretty standard stuff like: my ($var1, var2) = ($columns[1]->as_trimmed_text, $columns[2]->as_trimmed_text); ..except that there's a few more columns so it continues on over a few more lines. I had ...

Java quick sort, reading from a user input file into any array (to be sorted)

What's up y'all, I am trying to write some code in Java that will read in the numbers from a file (one # on each line of .txt file) put them into an array, and then run quick sort on the array. Eclipse is showing some red that I am having trouble with. My errors are marked with comments, and what the error is, if anyone can help me get ...

Objective-C, sorting an array based on a objects instance variable.

I'm working on a game like Rodents Revenge, just to point out where I'm coming from with this question. I'm using the cocos2d game engine aswell... I have a layer that contains about 168 blocks, these blocks are a subclass of a Sprite. Each block contains two instance variables that are integers, one for the xGridLocation and yGridLocat...

How to pass JSON array correctly?

i am trying to create a fade effect with the following...ive been told im nearly there apart from the passing of the json array. At the moment no images are displayed. //generate all the boxes $.get('images.php',function(data){ for (var i=0; i < totalBoxes; i++){ var randomImage = data[Math.floor(Math.random() * data.length)];...

Does PHP copy variables when retrieving from shared memory?

If I run an shm_get_var(), will it return a "reference", keeping the data in shared memory? I'm wanting to keep an array about 50MB in size in shared memory so that it can be used by multiple processes without having to keep multiple copies of this 50MB array hanging around. If shared memory isn't the answer, does anyone have another id...

Does the array key determine array size in C++?

im storing some settings for objects in an array. the id's of objects are used as the key. the id's start from 100000 and go up. if i was to input data for an object with id 100 000, would cpp automatical create 99999 blank key entries starting from 0? ...

Array to store in Cookie (JS)

On a site I'm coding, there's a Partners page that contains, amongst other things, a phone number for that business to view. My boss wants this phone number to be hidden then, upon being clicked, appear (I'll fade it in with jQuery) and then log the click. This will allow him to keep track of the amount of people that have shown interes...

How to check the end of the array

I have an array of type int matrix[][] and it has values of 0 and 1 000000000 101010111 000010100 110011001 the values are different to the above, however this is a random example. What i need to do is, loop through the first row when column = 0 and row = 0 adding 1 to row to loop if a one is found add it to a variable when i ...

Multi-dimensional array keys - strange behaviour

I am using a multi-dimensional associative array to keep track of monthly totals, then I want to loop through it using foreach and output the contents. The totals for each inner array are kept in element 12, and only want each array to output if the total is > 0, except "Total", which I want to output even if it is 0. foreach($years...

sorting elements javascript

I'm looking for a way to sort my elements, but it isn't as easy as it sounds. Please let me explain My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all thumbnails are inside one div xx xx xx xx xx xx xx xx xx The first column (6 x's) is visible and when you click on a button the ...

Best way to store and retrieve this..?

I've been trying all night, and talk of maps, arrays, vectors and hash_maps have filled my head. im just confused now. i posted a previous question here: http://stackoverflow.com/questions/1687085/c-map-really-slow problem was fixed but it seems map's are still not fast enough. i need to keep adding data. data is added ALOT during run t...

How to get array size for dynamic created memory

Consider an example: void main() { int *arr; arr=new int[10]; } How can I know the size of arr? ...

Make an object searchable with array_search in PHP

Hi, I would like to make a class in PHP such as it would be searchable with PHP native method array_search. Currently my class implements IteratorAggregate and Countable, which allows me to do foreach on it. There is a couple of other SPL interfaces (SeekableIterator, ArrayAccess, etc...) which seems to maybe fit, but I would like to k...

Square brackets in HTML form arrays. Just conventional or with a meaning ?

I frequently see, in particular in the PHP world, the following writing if you want to create a FORM array. <input name="MyArray[]" /> <input name="MyArray[]" /> with the square brackets []. Nevertheless, the submit operation just passes the same key entry twice. It appears that the [] is just conventional that maps nicely to the PHP ...

Initialize a 2D-array at declarationtime in the C programming language

How do I initialize a 2D array with 0s when I declare it? double myArray[3][12] = ? ...

Javascript: How to sort an array of records by values in one of the fields?

Hi, Suppose I have an array of records: [{a:0,b:0},{a:2,b:1},{a:1,b:2}] which I wish to sort in descending order of the "a" field in each record, and alert the sorted records as a new array (ie the new array would be [{a:2,b:1},{a:1,b:2},{a:0,b:0}]) - how would I go about this? I've tried a few approaches but am banging my head against ...

Using a pointer to a local variable in Dynamic SQL

I am having trouble with dynamic SQL. Early in my code I assign data to a bunch of local variables. I want to access these later in my code and use the data values. The code example below shows a simplified example to explain what I am trying to do. -- ---------------------------------------------- -- Declare and set the data into a ...

Sorted array Big o notation

Hello I just have a simple question, why is the big O notation of a sorted array O(log N)? It will be a sorted array. ...

PHP - Does mysql_fetch_assoc return a two dimensional array?

when $query = 'SELECT * FROM users'; and there are multiple columns/rows, does mysql_fetch_assoc($result) return a two-dimensional array? Can I draw each row by simply saying: array_pop(mysql_fetch_assoc($r)) thanks! ...

Append value to multidimensional array

function append (array, value, dimension) { switch (dimension) { case 0: array.push( value ); break; case 1: array[array.length-1].push( value ); break; case 2: array[array.length-1][array[array.length-1].length-1].push( value ); break; case 3: array[array.length-1][array[array....