arrays

How to initialize 3D array in C++

How do you initialize a 3d array in C++ int min[1][1][1] = {100, { 100, {100}}}; //this is not the way ...

Algorithm to find a number and its square in an array

Hello I have an array of integers. I need an O(n) algorithm to find if the array contains a number and its square; one pair is sufficient. I tried to do it myself, but I have only managed to find a solution in O(n2). Thanks Edit: like I was asked: I thought about using counting sort, but the memory usage is too big. ...

Problem in array search

I am trying to find values inside an array. This array always starts with 0. unfortunately array_search start searching with the array element 1. So the first element is always overlooked. How could I "shift" this array to start with 1, or make array-search start with 0? The array comes out of an XML web service, so I can not rally modi...

VBScript: Error 10023 in : Array index out of range (trouble when reusing an array variable)

Using Sax ActiveX Scripting (long story), I have 3 nested if statements which reuse the same return variable. Script looks roughly like: Dim rtnArray As Variant If variable1 <> "" Then ' Perform SQL query against DB2 database rtnArray = DB2SQLSearch(Query) If UBound(rtnArray) = 0 Then ' ditto rtnArray = DB2SQ...

preg_match a "shortcode" to create an array with semantic array keys.

How would I preg_match the following piece of "shortcode" so that video and align are array keys and their values are what is with in the quotes? [video="123456" align="left"/] ...

how to extract the exact data from an array in php

i got this array from an database...how to get the exact value attribute...... Array ( [0] => TRowResult Object ( [row] => tests [columns] => Array ( [a21ha:link_0] => TCell Object ( [value] =>testsample ...

Parallel array assignment in PHP.

Most languages make it easy to take an array like [1, 2, 3] and assign those values to variables a, b, and c with a single command. For example, in Perl you can do ($a, $b, $c) = (1, 2, 3); What's the corresponding trick in PHP? [Thanks so much for the lightning fast answer! I know this is a trivial question but all the obvious goog...

Java integer to byte array

I got an integer: 1695609641 when I use method: String hex = Integer.toHexString(1695609641); system.out.println(hex); gives: 6510f329 but I want a byte array: byte[] bytearray = new byte[] { (byte) 0x65, (byte)0x10, (byte)0xf3, (byte)0x29}; how can i make this?? :D thnx! ...

How do I insert an array entry at initialisation time?

Given an array of strings, how do I create another array that has another entry inserted at initialisation time? Eg. I want to do something like this: var newArrayOfStrings = new string[] { "inserted entry", anotherArrayOfStrings } (I know I can do this by getting a count and then copying; but I think it should be possible to do this ...

Error working with structs and pointer arrays: incompatible types in assignment

#define STRMAX 50 struct Person { char sName[STRMAX]; int iAge; }; typedef struct Person PERSON; int main() { PERSON *personen[1]; personen[0]->sName = "Pieter"; personen[0]->iAge = 18; return 0; } This code generates an error on personen[0]->sName = "Pieter"; saying incompatible types in assignment. Why? ...

Which is the more efficient way to store this ordered pair in php?

Which of the following two data structures is "better"? array('key'=>array(1,2,3,4)) OR: array('key',array(1,2,3,4)) i.e., is it better to store the array as the second element in a two element array, or as the single element in an array with the key, 'key'. Assume that for my purposes, in matters of convenience, they are equivale...

array_combine stuck when there is no value in first array

i m using array_combine() but it display error when in first array there is no value. how to get rid of this EDIT: First array Distance_Array Array ( [0] => ) School_ID_Array Array ( [0] => ) and i m using $Coverage_ Array=array_combine($School_ID_Array,$Distance_Array); which results Coverage_ Array Array ( [] =...

How to get the most represented object from an array

Hi, I have an array with some objects, and there are several objects that are alike. E.g: fruit = [apple, orange, apple, banana, banana, orange, apple, apple] What is the most efficient way to get the most represented object from this array? In this case it would be "apple" but how would you go out and calculate that in an efficient wa...

Passing arrays through fortran dll from vb.net app turning to single element arrays. Should i pass only the first element?

I have a VB.net console app and I am opening a function in a dll written in fortran. I am passing 3 arrays through the function by reference. When they come back out the otherside they ahve all tunred to arrays of only one element. And that element is 0. I read on the internet somewhere that when doing this kind of thing it is a good...

combine two (or more..) multi-dimensional arrays in php

Hi, I have a query that I run several times with different parameters. I am using an xml parser to return the results to jQuery. I can't seem to find a way to combine the results on the first 'node' without overwriting the first entry. Simplified code sample: $temp1 = returnArray(0); $temp2 = returnArray(1); $data = array_merge($t...

Sorting a multi-dimensional [,] array in C#, composed of integers

I have the following array: private int[,] testSamples = new testSamples[101,101]; It's supposed to represent a roster, with column 0 to 100 and row 0 to 100. In this rosters, various chemical liquids are dropped. The person I'm doing this for wants to work in such a way that he can take care of the container with the most liquid in i...

How to sort array in javascript?

var arr = []; arr.push(row1); arr.push(row2); ... arr.push(rown); How to sort by row['key']? ...

How to access a property of an array in Ruby

I have this object of class Array >> answers_to_problem => [#<Answer id: 807, problem_id: 1, player_id: 53, code: "function y = times2(x )\r\n y = 2*x;\r\nend", message: nil, score: 12, output: nil, hide: nil, create d_at: "2010-02-02 11:06:49", updated_at: "2010-02-02 11:06:49", correct_answer: nil, leader: nil, success: true, clo...

PHP how to assign class property variables conditionally

Hi, I'm new to php classes, arrays, etc, so pls excuse me if I don't use the correct terminology. What I'm looking for is how to assign easily values to properties from a class without having to depend on "if" statements. For example: Suppose I have an instance of a class test, and "test" has a property "employee" (hope this is the co...

Django: How do I get an array from a QueryDict in a template?

hi, I've got the following QueryDict object in my request.session. <QueryDict: {u'category': [u'44', u'46'], u'cityID': [u'null'], u'countryCode': [u''], u'mapCenterLng': [u'2.291300800000009'], u'mapZoom': [u'12'], u'mapCenterLat': [u'47.10983460000001'], u'price_range': [u''], u'textbox': [u'']}> In a template try to get the catego...