arrays

Finding nr of an array value based on a string that exist in the array

Hi. I have an array for all the cars in a online game I'm making that look like this: $GLOBALS['car_park'] = array ( "Toyota iQ3", "Think City", "Lancia Ypsilon", "Smart fourtwo", "Chevrolet Matiz", "Mazda 2", "Peugeot 107", "Nissan Micra", "Mercedes-Benz 310" /* dårlige biler */ , "Lexus IS-F", "BMW M3 CSL",...

C++: Overwrite an element in a new-created array

Hi, If I have an array created like this: MyType *array = new MyType[10]; And I want to overwrite one of the elements, do I have to delete first the old element like this: delete &array[5]; array[5] = *(new MyType()); Or is this completely wrong and do I have to work with something like "pointers to pointers" to fix this job? If s...

perl print array from subroutine

#! /usr/local/bin/perl sub getClusters { my @clusters = `/qbo/bin/getclusters|grep -v 'qboc33'`; chomp(@clusters); return \@clusters; } ummm okay .. how do I get at this array to print since ... foreach $cluster (getClusters()) { print $cluster."\n"; } doesn't seem to work. Thanks. ...

Is there a JavaScript function to serialize and unserialize arrays like PHP?

I'm making a PHP model to store a serialized array in a database. The array is then accessed via AJAX through an HTTP request. Is there a JavaScript function to serialize and unserialize arrays like PHP? EDIT: This is the php function http://uk.php.net/manual/en/function.serialize.php ...

jQuery / PHP - sort html list by PHP array values?

I have a list like this: <li> <input value="1" name="bla[]" /> </li> <li> <input value="2" name="bla[]" /> </li> <li> <input value="3" name="bla[]" /> </li> (always the same order) and a array like this array('3', '1', '2'); but the order of the values in the array can change anytime. Can the list above be sorted with jQuery based...

rails - Finding intersections between multiple arrays

Hi, I am trying to find the intersection values between multiple arrays. for example code1 = [1,2,3] code2 = [2,3,4] code3 = [0,2,6] So the result would be 2 I know in PHP you can do this with array_intersect I wanted to be able to easily add additional array so I don't really want to use multiple loops Any ideas ? Thanks, Alex...

PHP - Sort array elements based on another array's elements :)

so I have two arrays. one of them looks like this (it's values or the number of elements can change): array('4dec' , 'def3', 'a3d6', 'd12f'); and the other: array(array('id' => 'd12f', 'name' => 'John'), array('id' => 'a5f1', 'name' => 'Kathy'), array('id' => 'def3', 'name' => 'Jane'), array('id' => 'a3d6', 'name' =...

perl split string into 2d array

Okay .. this works ... sub getApSrvs { my %apsrv; my $cluster; foreach $cluster (getClusters()) { $apsrv{$cluster} = [split('\s+', `/$cluster/bin/gethosts -t app|sort -u`)]; } return %apsrv; } ... now how in the ham sandwich do I get this to print like so $cluster --> $hostname okay I added : my %apsrv = getApSrvs(); for...

array to hash in perl

I have a source list from which I am picking up random items and populating the destination list. The item that are in the list have a particular format. For example: item1{'name'} item1{'date'} etc and many more fields. while inserting into the destination list I check for unique names on items and insert it into that list. For this...

Fastest way to convert JavaScript NodeList to Array?

Previously answered questions here said that this was the fastest way: //nl is a NodeList arr=Array.prototype.slice.call(nl); In benchmarking on my browser I have found that it is more than 3 times slower than this: arr=[]; for(var i=0,n; n=nl[i]; ++i) arr.push(n); They both produce the same output, but I find it hard to believe th...

Multiple instances of a single object in a Rails Array?

G'day guys, trying to build a small invoicing system (that can generate PDF's using prawn), but am having an issue with generating multiples of indivdual items in the array. I have the Invoice class which has_many :items, but when I try to add a multiple of an item to the invoice, it won't actually add that to the invoice and it doesn't ...

Listbox clears all items during datasource change

When I change the datasource of my Listbox all items are cleared, when loading new data into this Listbox it stays clear. I have another ListBox right new to this one with the same refresh code but that one refreshes perfectly. private void RefreshContacts() { this.ListContacts.DataSource = null; this.ListContac...

PHP newbie CURL and array question

UPDATED: I've simplified the code (tried to) I'm trying to download a series of images as set in an array, but something is clearly not right: function savePhoto($remoteImage,$fname) { $ch = curl_init(); curl_setopt ($ch, CURLOPT_NOBODY, true); curl_setopt ($ch, CURLOPT_URL, $remoteImage); curl_setopt ($ch, CURLOPT_RETU...

Sorting an array by a certain key

I have the following array: Array ( [Places] => Array ( [public] => 0 [entities] => Array ( ... ) ) [Issues] => Array ( [public] => 1 [entities] => Array ( ... ...

An algorithm to solve a simple(?) array problem.

Hello! For this problem speed is pretty crucial. I've drawn a nice image to explain the problem better. The algorithm needs to calculate if edges of a rectangle continue within the confines of the canvas, will the edge intersect another rectangle? We know: The size of the canvas The size of each rectangle The position of each recta...

How to modify Hash to enable access of element 'hash[:a][:b]' by shorter 'hash[:a,:b]' in Ruby?

I would be happy to access any element of multi-dimensional hash-array by a shorter expression h = {a: {b: 'c'}} # default way p h[:a][:b] # => "c" # a nicer way p h[:a,:b] # => "c" # nice assignment h[:a,:b] = 1 p h # => {:a=>{:b=>1}} I realize that in this way one eliminates the possibility to have a hash key being an array. {[...

How do I make an array of CGFloats in objective c?

So I'm working on a simple iPhone game and am trying to make a local high score table. I want to make an array and push the highest scores into it. Below is the code I have so far: CGFloat score; score=delegate.score; NSInteger currentindex=0; for (CGFloat *oldscore in highscores) { if (score>oldscore) ...

Convert Octet string to char array

There is a server which sends some data in Octet strings. For example it is sending 00405080065233E like this, then I need to convert this into a string and store it into a buffer. If I decode that converted string it has give the same 000405080065233E octet string again. How can I do this? Can anybody suggest some solution? ...

PHP arrays break apart and rebuild

A bit of background The project I am working on requires me to build a dynamic form, essentially a page is created and from there a user can add as many news articles to that page as they wish, my issue is that this is an inherited system and I have to jump through a million different hoops, one of which is the string sanitation, they w...

Get an asset's numerical position in an array in Ruby on Rails

Hi All, I'm working with a list of assets, sorted alphabetically (through another method). I would like to assign a value to the "position" key, which essentially just says where this particular asset appears in the ordered list of all assets. Here is the code I'm working with now (:position left blank on purpose): @active_resources.ea...