arrays

PHP: Session 2-Dimensional Array - Track Viewed Products

I'm trying to create an array to display the last 5 products a customer has viewed. The array is a 2 dimensional array like below... $RView= array( array( ID => "1001", RefCode => "Ref_01", Name => "Name_01" ), ... array( ID => "1005", RefCode => "Ref_05", Name => "Name_05" ) ); The array values are retrieved from ...

C++ - Passing Arrays To Methods

Hello, Here is a function similar to the one I've defined: void Function( BYTE *data ); What I would like to do is something like this: Function( new BYTE { 0x00, 0x00 } ); ...

Multidimensional Arrays in PHP

How do i add items into a multidimensional array? Basically i am making an application which calculates what people are buying in a suppermarket and how much of it. Sue buys 2 tubs of butter and 1. toothpaste John buys 1 peach and 1 banana. I think the array would look something like this $sue[butter] = array(); $sue[butt...

"Direction" of bidimensional arrays in C

Hi, as a C newcomer I'm a bit confused about bidimensional arrays. If I want to represent a matrix of 3 rows and 5 columns, I guess the correct declaration is: char a[3][5]; So, is this an array of 3 pointers to 5 arrays of chars or what? How come whenever I try to cycle through it like the following it seems to read the wrong resul...

C#: custom array sorting

Hi, I would like to sort an array of strings in a directory, given a custom mapping (it's actually a sorting of stock names based on their sector). I am unsure of what data structures to use to represent the mapping, and how to write the custom sort method. So for instance, suppose I had the following string array: string[] fileNam...

Java: Converting arrays of arrays to collections of collections and vice versa.

Please suggest some elegant way to convert arrays of arrays to collections of collections and vice versa in Java. I suppose there's no convenience methods in the Java API, right? public static <T> T[][] nestedCollectionsToNestedArrays( Collection<? extends Collection<T>> source){ // ... ? } public static <T> Collection<Collecti...

Randomizing elements in an array?

I've created a site for an artist friend of mine, and she wants the layout to stay the same, but she also wants new paintings she'd produced to be mixed into the current layout. So I have 12 thumbnails (thumb1 - thumb12) on the main gallery page and 18 images (img1 - img18) to place. The approach I thought of was to create an array of ...

How to copy all different elements from an array in c#

Lets say there is an array like this: double [] numbers = new double[] {1,1,2,2,5,7,7,7}; I want to copy only the different numbers to a new array (the result should be numbers = {1,2,5,7}) in a time efficient way. I know how to do it in a time inefficient way - by looking if the next number is the same as the one before and continuin...

returning IList<T> vs Array in C#?

I was recently asking someone why he preferred to return a strongly-typed array over an IList. I had always thought that programming against an interface was the most flexible and best way program when faced with a project having a long life. So it struck me as odd when he replied: We typically prefer immutable types over mutable o...

Why won't a derived class work in an array? (C++)

I've created a class, called vir, with a function move: class vir { public: vir(int a,int b,char s){x=a;y=b;sym=s;} void move(){} }; (It's derived from a class with variables int x, int y, and char sym) I have derived a class from this, called subvir: class subvir:public vir { public: subvir(int a,int b,char s){x=a;y=b...

Help need Allocatable Array in FORTRAN

Hi, All. I'm really having trouble with Allocatable array. I have to copy all information from a file into allocatable array. The file is like this: 3 3 5 2 1 4 0 3 is the number of points other six numbers shows points on the graph in (x, y) form. So (3,5), (2, 1), (4,0) are the points. But I have problem to make these number as...

Save NSMutableArray to disk

Hello, I have an NSMutableArray that holds objects of the type Person (NSString,NSString,int) I am looking for a easy way to save this array to disc and load it again later. I read alot about serialization but I never have done that. Maybe it's not the easiest way for me after all. ...

Creating a byte array using the long datatype?

Most of the time when we read the file stream into a byte array, we would write the following code:- Dim inputStream As New System.IO.FileStream(filePath, IO.FileMode.Open) Dim fileLength As Integer= CType(inputStream.Length, Integer) Dim input(fileLength) As Byte Using inputStream inputStream.Read(input, 0, fileLength) End U...

Referencing for element in a PHP array

Answer is not $array[0]; My array is setup as follows $array = array(); $array[7] = 37; $array[19] = 98; $array[42] = 22; $array[68] = 14; I'm sorting the array and trying to get the highest possible match out after the sorting. So in this case $array[19] = 98; I only need the value 98 back and it will always be in the first positi...

C++ Problem initializing an object twice

Hi, I'm relatively new to C++ and am having a hard trouble understanding the instantiation of object and pointers to objects. Whats the difference between these two declaration in terms of memory and usage? : MyClass obj1; MyClass *obj2; And also the specific problem I am having is that I have a class which has an unsigned short arra...

SFINAE with invalid function-type or array-type parameters?

Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main() { char c[sizeof(f<void()>(0)) == 2]; } I expected it doing SFINAE and chosing the second overload, since substitution of T into T[1] yields void [1]() Which is an invalid type, of course. Adjustment of parameter...

D2009 problems with array of char - how can I `elegantly` fix my code?

Going through some of my older Delphi projects and upgrading them to D2009, as I find this version a great improvement (Generics.Collections - wow! ;)) to all previous releases, I encounter various problems. This one I managed to solve but the solution does not seem half as elegant as I believe it could be. (Note, I haven't written Delph...

How can I iterate over multiple lists at the same time in Perl?

I need to create a text file (aptest.s) that Ican use to read into another program. I am using Perl because I have a large list to work from. My code is as follows (which does not give the desired output - shown after code and actual output). Any help would be appreciated. #!/usr/bin/perl -w chdir("D://projects//SW Model ODME"); @link =...

How to convert this MPTT array into a tree structure in PHP?

I've got hierarchal data in the database, stored in Modified Preorder Tree Traversal format. I'm pulling the data in a query that looks something like "SELECT ID, Left, Right, Name, etc FROM Table ORDER BY Left;". I'm trying to convert this data from a flat array the DB gives me into a tree-structure which I will then output as JSON wi...

Search inside Array for Value on a MYSQL Output

The code below doesn't seem to work or find anything on an array. I'm using "in_array" to search for the needle in the stack. I also tried exploding the contents with comma separated and won't work. Any suggestions? Also I tried "array_search". $q4 = "SELECT domain_name,slots_config.bid FROM slots_pid,slots_config,slots_sites WHERE slo...