arrays

Sorting Items in Rails Controller Method

I'm having an issue writing a controller action that takes Post ids passed as a parameter and sorts them into a specific order before publishing them. The Posts have a position attribute (I'm using acts_as_list for sorting), and are either published or unpublished (searchable with the named_scopes Post.published and Post.unpublished, ac...

Repeat array to a certain length?

I'm having an array for example with 4 elements array("a", "b", "c", d"); what is the fastest way to repeat this array to create a new array with a certain length, e.g 71 elements? ...

sort an array base on key

i have an array like this: Array ( [0] => Array ( [title] => some title [time] => 1279231500 ) [1] => Array ( [title] => some title 2 [time] => 1279231440 ) [2] => Array ( [title] => some title 3 [time] => 127922...

How to add and remove array value in jquery

add and remove array value in jquery? I have array of data var y = [1, 2, 3]; I want to remove 2 from array y. Any one have idea how to remove particular value from array using jquery? I have tried pop() but its working like stack. ...

Add dynamic instances of MovieClips to an array.

I'm trying to add an instance of a MovieClip inside an array. Inside the House Class is a property called HouseObjects. Inside that array, I created a Comp and a Light class. MovieClips are dynamically placed on the stage, via linkage. The MovieClips also act as "toggle buttons." If the button state is ON, value is 1. If the button state...

PHP Array vs MYSQL Queries speed optimization

I'm trying to make my php mysql driven pages as fast as possible. I've got a fairly standard website with a left-column menu with lists of articles and recipes (loaded from the db) and then on the main content there are some randomly changing articles with clipped previews and also random recipes. What I've got at the moment is one sql ...

JavaScript .push() inside function is overriding global variable

Hi! I have the following problem with .push() method: var myArray = ["a", "b", "c", "d"]; function add(arr) { arr.push("e"); return arr; } add(myArray); // myArray is now ["a", "b", "c", "d", "e"] Why it overrides myArray? Can't understand that... ...

PHP Search Array Question

I need to have an array_search search my array strictly making sure that the item is identical (meaning the whole thing is the same thing as the input value). I know about the third variable in a array_search() function in PHP - the Strict one, but I don't want it to check if its the same instance, as it is not. How would I do this? Her...

PHP object default return value

I have a function which returns object array like that: <?php function sth() { return (object) array( "obj1" => $obj1, "obj2" => $obj2, "obj3" => $obj3 ); } $obj = sth(); echo $obj; ?> Here I want to define $obj's default value.It will return default value instead of $obj1,$obj2,$obj3. How can I define a defa...

Python's list comprehensions and other better practices

This relates to a project to convert a 2-way ANOVA program in SAS to Python. I pretty much started trying to learn the language Thursday, so I know I have a lot of room for improvement. If I'm missing something blatantly obvious, by all means, let me know. I haven't got Sage up and running yet, nor numpy, so right now, this is all quit...

add_action function in wordpress

well im learning to create a wordpress plugin i downloaded one and read the codes, and i saw this i assume 'foo' is the tag where it will add action to.. but what does the array() exactly do? add_action('foo', array('foo1', 'foo2')); i looked at http://codex.wordpress.org/Function_Reference/add_action and there is no clear definition...

passing an array in intent android

So I've always been under the assumption that you can't pass arrays between activities with extras. But I was just going through the Bundle class docs and saw putStringArray(String key, String[] value) and public String[] getStringArray (String key). Are these new? They both say since API lvl 1, but I don't remember being able to pass ar...

How do I redistribute an array into another array of a certain "shape". PHP

I have an array of my inventory (ITEMS A & B) Items A & B are sold as sets of 1 x A & 2 x B. The items also have various properties which don't affect how they are distributed into sets. For example: $inventory=array( array("A","PINK"), array("A","MAUVE"), array("A","ORANGE"), array("A","GREY"), array("B","RED"), array("B","BLUE"), a...

How to store MySql values as Multidimensional Array using PHP

Hi, I have a database table as follows. <table border='1'><th>Id</th><th>FirstName</th><th>last Name</th><tr><td>1</td><td>Tom</td><td>T</td></tr><tr><td>2</td><td>Jerry</td><td>J</td></tr></table> I would like to store all values as a multi dimensional array using php(using a while loop to retrieve fields).That is, I would like the d...

PHP remove duplicate values from multidimensional array

We can use array_unique() for remove duplicate entry from a single multidimensional array in php.Is it possible to use with multidimensional array? It is not working for me! Here's what the array looks like Array ( [0] => Array ( [0] => 1001 [1] => john [2] => example ) [1] => Array ( [0] => 1002 [1] => test [2] => dreamz ) ...

Add rows to table even if not in array

Not sure how to title this, so I apologize if it's misleading or not understandable. What I have is an array, that array will have 1-4 arrays within it. I need a HTML table to output 4 columns, so even if the array only has one array in it, it still needs to output for columns. The issue I am hitting is that the columns need to match up....

VB.NET - Dimming an array of processes.

Trying to dim a certain amount of process (determined by Environment.ProcessorCount) to run several processes which do not support multi-threading. I have already Dim'd proinf(6) as Process.ProcessStartInfo because I have designed a queue for the processes and this encounters no errors. Any help is appreciated! ...

jQuery - split() arrays with only one match = undefined

Hi, I have a problem with the split() function. I get the error undefined but it dont know why :/ It is easier to explain with a working example: http://www.jsfiddle.net/V9Euk/415/ $(function start() { css('#div { font-color:#ff0000; border:1px solid #00ff00; }', '#div_2 { font-color:#ff0000; }', '#line2 { font-color:#00ffff; }');...

Changing static array

Hi, I have a static variable declared in a file: static char *msgToUser[] = { "MSG1 ", "MSG2 ", }; Inside one of the methods of a class I'm doing this: void InfoUser::ModifyMsg( BYTE msgIdx, char *msgString ){ strncpy( msgToUser[ idx ], msgString, DISPLAY_SIZE ); } When I do the strncopy ...

Javascript Array Undefined

Hi Guys I keep getting the error links[i] is undefined. I define it explicitly and yet it keeps giving me that error -- any ideas? I am trying to do unobtrusive image rolovers on 5 links that I have. function loadImages(){ path = 'uploads/Splash-4/nav/'; links = new Array(); for (i=1;i<=5;i++){ var id = "link-"+i...