arrays

How can I use a string to get a value from a multi dimensional array?

Say this is my string $string = 'product[0][1][0]'; How could I use that string alone to actually get the value from an array as if I had used this: echo $array['product'][0][1][0] I've messed around with preg_match_all with this regex (/\[([0-9]+)\]/), but I am unable to come up with something satisfactory. Any ideas? Thanks in a...

double type array use in J2ME

I have use Double type array, it works in Emulator but showing error in mobile, what is the problem?? ...

Dynamically referencing Javascript Array name without using Eval?

Given that EVAL is Evil how do I create an Array name dynamically: I have a bunch of Arrays and I need to reference different ones depending on what the user clicks. This bit of code gives me the array object: (eval(calendarObject.id + '7')) But eval is bad, so how to do I construct an Array name and then reference it? Here's a bi...

jQuery javascript array handling

Noobie muddling his way through an Ajax autosuggest form: I've got most of it working, but need to break things down a bit, so I can understand how jQuery refers to things. EDIT: This is my working code, thanks guys. Some problems with delay on the ajaxdiv, not hanging around, but I am working on that ;) function jQajax(ipfield,ajd,dbt...

How to notate nested arrays or structs or classes the hungarian way?

i have an array wich contains another array Would i notate it this way? pseudocode: rgrgTest = newArray(2) What if the array contains i.e. a struct? pseudocode: rggrTest = newArray(2).newStruct() Or this way i.e. if i want to classify the data types of the struct? pseudocode: rggrlstlTest = newArray(2).newStruct(int id, str desc,...

Odd generics behaviour of List.toArray(T[])

I came across something very basic but extremely bewildering today. I needed to convert a list to an array. The list contained String instances. Perfect example of using List.toArray(T[]), since I wanted a String[] instance. It would not work, however, without explicitly casting the result to String[]. As a test scenario, I used the fo...

PHP recursive search and replace array elements

Hi all, I want to recursively search and replace elements in an array. The array is tree based so looks like Object Children Object type A Object type B Object Children Object type A Object etc. I want to be able to replace certain items with other items, so for example, I want to replace all entries in the ...

How do I create and use a byte array in perl?

$var = pack "C2", 0x20, 0x30; seems to work well enough, but now how do I address the elements of the array? Make changes to elements? In-place if possible. The pack/unpack semantics are not very friendly. Currently I'm using substr($var, $index, 1, substr($var, $index, 1) + 10) to add 10 to elements in-place. And for intializers, i...

javascript array associative AND indexed?

can an array in JS be associative AND indexed? I'd like to be able to lookup an item in the array by its position or a key value.. possible? ...

How can I work with a multi-dimensional array in JavaScript?

I have a multi-dimensional array, no problem. How do I interrogator one of the arrays in order to ascertain if it actually holds any data? I am working with VS 2008 and what I can see in the debugger is, lets call the element x, is x{...}. However, if I try and use x.length i get the message 'undefined' - so how do I ascertain if the ...

Javascript for/in loops through properties, not indexes and returns strings.

Ok, I have this code: var room = [ { time: 0, people: 0 } ]; and then: time = 5; for( var i in room ) { if( room[i].time < time ){ spliceIndex = i + 1; } } console.log(spliceIndex); And the console reads: 01 - Which means the 1 is concatenated which further means that i is a string, and not an integer as expected. Casting t...

How can I determine if an element is contained in an Array without looping?

How can I check whether a particular element is inside an array? I don't want to manually write a loop for this; instead I want to use a JavaScript built-in function, maybe something equivalent to new Array(0,1,2,3,6,9,12,15,18).Contains(5) //return false new Array(0,1,2,3,6,9,12,15,18).Contains(1) //return true Edit the question t...

Using Set::extract in CakePHP

I have a query to get all the compatible phones in a specific country, and in my controller I'm using Set::extract to reduce the untidy result array to just an array of product names. $results = $this->Country->compatiblePhones($country); $compatiblePhones = Set::extract('/p/product_name',$results); $this->set('compatiblePho...

I have two unordered integer arrays, and i need to know how many integers these arrays have in common

I'm working in a LAMP environment, so PHP is the language; at least i can use python. As the title said i have two unordered integer arrays. $array_A = array(13, 4, 59, 38, 9, 69, 72, 93, 1, 3, 5) $array_B = array(29, 72, 21, 3, 6) I want to know how many integers these array have in common; in the example as you see the result is 2...

Changing a nested (multidimentional) array into key => value pairs in PHP

I have an multidimensional array that looks like this: Array ( [0] => Array ( [ClientID] => ec2173de2134fdsfg4fsdffcb4b5205 [Name] => ABC Widgets ) [1] => Array ( [ClientID] => e5dfgfdg2d760f640aadfgdfgdfg47b [Name] => Acme Co ) [2] => Array ...

Block user from moving anywhere

I have made a game which is nearly identical to Popcap's Atomica. (http://www.popcap.com/gamepopup.php?theGame=atomica) It's almost finished, except for one important function; blocking the user from moving spheres anywhere. Like, if there is a wall of other spheres in between the sphere the user is trying to move, and the field it is t...

making graphs with xCode

Hi I need to graph some arrays to analyse signals, I have a cocoa project going. Can anyone tell me where I can find tools to simplify this task? Basically i want to display my arrays like on a graphing calculator. ...

Why do we have to call contructor for each element in an Array

its kinda basic question but still bugging me.. why doesnt MyObject [] myobject = new MyObject [10]; doesnt allocate 10 objects? why we have to call new on each individual object aswell. myobject [0] = new MyObject(); . . . myobject [9] = new MyObject(); is that so or I am making some silly mistake? :) ...

Java: How to convert int[] to byte[]

Hi, I have an array of integers which represent a RGB image and would like to convert it to the byte array and save it to the file. Does anyone know what's the best way to convert an array of integers to the array of bytes in Java? Thanks! ...

PHP - Check how many values in array

Can I check the number of values in an array, for example... $abc=array(); $abc[0]="asd"; $abc[1]="sadaf"; $abc[2]="sfadaf"; I want to check and store it(2) in a variable that array abc[] exists till $abc[2].. Thanks ...