arrays

php: check if certain item in an array is empty

In PHP, how would one check to see if a specified item (by name, I think - number would probably also work) in an array is empty? ...

.NET - I want to do this: Dim D as new Dictionary(of String, Array(OF MYOBJECT))

I'd like to create a Dictionary that is indexed by Strings: Dictionary(of String, ...) I'd like the Type after the comma to be an Array of MyObject's. If all I do is the following: Dim D as new Dictionary(of String, Array) I feel like I'm missing out on some performance very time I access a member: Dim Object1 as MyObject = MyDict...

In a java enhanced for loop, is it safe to assume the expression to be looped over will be evaluated only once?

Hi, In Java, a for-each loop. If I have a method that generates an array, called genArray(). In the following code, will the array each time be re-generated by calling genArray()? Or will Java call once the method and store a copy from the array? for (String s : genArray()) { //... } Thanks ...

Instantiate array in F# ??

In C# I'd write something like MyType arr = new MyType[10]; to alloc arr as array which has 10 items of type MyType. How to do the same in F# ?? let mutable arr = ????????????? ...

serialize problem in php

I want to serialize a multidimension array in php: $arr['foo'] = array('bar'=>'foo'); I'm going to pass $arr to an eval function and so i needed it to be serialized. When eval runs, it actually passes this as an argument to a class method, call it helper method, this helper method then takes that argument and converts it back to a rea...

actionscript: Using multidimentional arrays

Hi! I have problems defining indexed array with actionscript. The task is following. I have a board of point objects. I need to store them into one array, so I can access each point using simply it x,y coordinates. for example to get point one I want to be able use points[1][1], etc. I read the doc here http://livedocs.adobe.com/flex/...

How do I delete a random value from an array in Perl?

I'm learning Perl and building an application that gets a random line from a file using this code: open(my $random_name, "<", "out.txt"); my @array = shuffle(<$random_name>); chomp @array; close($random_name) or die "Error when trying to close $random_name: $!"; print shift @array; But now I want to delete this random name from the fi...

how to insert a new line after or before a given line number in a php array

I need to create a new line of data within an array where the line number = a given number pseudo code $info = array("Breakfast", "Lunch", "Dinner"); $target = "1"; //define where i want new data, pushing other data down $inject = "Brunch"; $newarray = somefunction($info, $target, $inject); $newarray now looks like [0]Breakfast [1]...

clone line in array with array_splice and then store new array

I have CSV text thats stored in the session array as csv. The lines are terminated by ### and fields terminated by %%. I also have a line number of a line within that array which is CID, or the line which i want to clone. I need to find that line within the csv array, splice it, and then update the session variable with the spliced arra...

Why use an Array of more than two dimensions?

I am having trouble wrapping my head around the concept of an array with more than two dimensions, why you would need one, and how you would use it. For example, how would you go about representing the following data in a multidimesional array? Sex: Male | Female Hair Color: Blond | Brunette | Black Eye Color: Blue | Brown | Green | H...

Having Trouble with Mutable Array to load sections in a Table View from Plist

Plist loaded in AppDelegate with following structure: Root ----> Dictionary Test Item ----> Array Item 1 ----> Dictionary HeaderTitle ----> String ----> Section 1 Items ----> Array Item 1 ----> Dictionary FirstName ----> String ----> Any Name SecondName ----> String ----> Another Name CellIcon ----> String ----> Icon.gif View -...

Javascript how to know if an array is subarray of another

How could I do the following in javascript in efficient way? I've counter of 7 items(item0, item1, item2...item6) in order.. like in counts = [0,2,0,5,6,0,9]; There are 3 mutually exclusive groups: group1: item0, item1, item2 group2: item3, 4, 5 group3: item6 A group is considered selected if and only if counters of the group member ...

splitting an array at a given line into two parts, inserting another line, and rejoining them

I have an array full of sub arrays. I need to break apart the first array at a given line number, and then insert a new line, and then combine them all back into their original structure. This is what im working with now $csvpre = explode("###", $data); $i = 0; $bgc = 0; foreach ( $csvpre AS $key => $value){ $info = explode(...

Fastest way to zero out low values in array?

So, lets say I have 100,000 float arrays with 100 elements each. I need the highest X number of values, BUT only if they are greater than Y. Any element not matching this should be set to 0. What would be the fastest way to do this in Python? Order must be maintained. Most of the elements are already set to 0. sample variables: a...

Can I use array_filter() on a class array?

I'm attempting to intercept and filter items out of a class set array, $this->_vars, in a stripped down version of Smarty (not my choice :| ) Here's what I've been attempting to use: Class callback function private function callback_check($var){ if(!in_array($var['link_id'], $this->returned_array['items'])) return false; else return...

Removing Array Elements in Python while keeping track of their position

Hi! I'v got two numpy arrays. The first array contains some zeros (which are distributed randomly over the length of the array), which I would like to remove. My issue is that I would also like to remove the entries of the second array at the index positions where the first array elements are zero. I only came up with a very cumbers...

Overloading array insertion?

I'm processing a XML with minOccurs and maxOccurs set frequently to either 0, 1, or unbounded. I have a schema describing this cardinality, together with the specific data type. I'd like to construct a (Delphi) class which keeps track of the cardinality, together with an array whose dimensions are to be validated based on the minOccurs a...

Django and HTML arrays

I have a form with this inputs: <input name="person[name]" value=""> <input name="person[surname]" value=""> <input name="person[age]" value=""> when I submit, how can i assign that html array to a variable, cause request.POST.getlist('person') doesn't work, i been checking for other post but the only one i found doesn't have anything...

C# Check Object Array For Duplicates

I have an array of Customer[] objects, and I want to use it to create a Dictionary<Customer, string>. What is the easiest way to examine the array for duplicates before I load the Dictionary? I want to avoid "ArgumentException: An item with the same key has already been added". Thanks. ...

Every element in an array being incremented simultaneously when only one should be.

I am using the following code to increment the elements in a 2d array surrounding a given element. EmptyCell = {number: 0}; //This has several parts in the actual code. list = new Array(); function init(w,h){ for (var x = 0; x <= w; x++){ list[x] = new Array(); for (var y = 0 ; y <= h; y++){ list[x][y]...