arrays

Problem: items from array (AlertDialog)

Hi all, Thanks to help people! I use an AlertDialog with list (singlechoice->radioButtons). When I choose an item from the list, a toast come and I do a setText of the item on a textView. Everything works when I declare my items like this: ((ImageButton)findViewById(R.id.pickPays)).setOnClickListener(newOnClickListener(){ p...

PHP: get array element

Why does this code not work? echo explode("?", $_SERVER["REQUEST_URI"])[0]; It says syntax error, unexpected '['. Oddly, this works: $tmp = explode("?", $_SERVER["REQUEST_URI"]); echo $tmp[0]; But I really want to avoid to create such a $tmp variable here. How do I fix it? After the helpful answers, some remaining questions: I...

passing .php array into a javascript code jquery/ajax

At the moment i have this piece of javascript code: //Display custom confirm box and delete multiple message $(document).ready( function() { $(".delete_button-multiple").click( function() { //Get message id as variable var id = $(this).attr("id"); var dataString = 'id='+ id ; var parent = $(this).parent(); //Display custom Confi...

Can I create a "view" on a Python list?

I have a large list l. I want to create a view from element 4 to 6. I can do it with sequence slice. >>> l=range(10) >>> lv=l[3:6] >>> lv [3, 4, 5] However lv is copy of a slice of l. If I change the underlying list, lv does not reflect the change. >>> l[4] = -1 >>> lv [3, 4, 5] Vice versa I want modification on lv reflect in l as ...

How to generate combinations of the elements in several arrays?

Hi, This is my first question here :) I have an array with a number of array children, each with unique values and would like to get all the possible unique combinations of those values. The number of arrays is known but may change over time. For example, array( [0] => array([0]=>'blue',[1]=>'red'), [1] => array([0]=>'sunny',[1]...

Sort values inside an Array on PHP

Hello, i have this array on php: Array ( [googlewindow] => 1 [google] => 6 [kei] => 1 [uutntpzlfcewtgfer] => 2 [dbq] => 2 [kexpi] => 1 [kcsi] => 1 [e] => 8 [ei] => 1 [expi] => 1 [ml] => 1 [function] => 5 [khl] => 1 [es] => 1 [time] => 2 [return] => 1 [new] => 3 [date] => 2 [gettime] => 2 [log] => 1 [b] => 2 [d] => 2 [c] => 6 [var] => 5 ...

How do I extract a "table" from an array of ActiveRecords in Rails?

I have several similar Models (ContactEmail, ContactLetter, ContactPostalcard). Each instance (record) in, say, ContactEmail, means a specific Email template was sent to a specific Contact. So, each one (e.g. ContactEmail) belongs_to :contact So, in ContactEmail model, there is an attribute ContactEmail.contact_id. Each Contact has a...

An easier way to define these variables?

$access_community = 1; $access_content = 1; $access_tools = 1; $access_administrator = 0; $access_moderator = 0; Just wondering if there's an easier way to write this using an array? This seems like overkill. Thanks! ...

Initializing a char array in C. Which way is better?

The following are the two ways of initializing a char array: char charArray1[] = "foo"; char charArray2[] = {'f','o','o','\0'}; If both are equivalent, one would expect everyone to use the first option above (since it requires fewer key strokes). But I've seen code where the author takes the pain to always use the second method. My...

PHP array_push not the right function, what to use?

array_push($array, getData()) gives me: Array ( [customer] => One [itemno] => Yellow Ribbon ) Array ( [customer] => One [itemno] => Blue Band ) Array ( [0] => Array ( [customer] => Two [itemno] => Red Tape ) ) But what I want is: Array ( [customer] => One [itemno] =...

PHP Grouping an Array

I have an array: Array ( [customer] => One [itemno] => Yellow Ribbon [price] => 1,2 ) Array ( [customer] => One [itemno] => Blue Band [price] => 0,5 ) Array ( [customer] => Two [itemno] => Red Tape [price] => 2,0 ) And I want to group it by customer like this: Array ( [One] => Array ( ...

Storing $_POST values in an array to save them to text file

I have multiple $_POST values which I want to store in an array to save to a text file. How would I go about doing this? PHP code: <?php $name=$_POST["name"] $email=$_POST["email"] $msg=$_POST["msg"] $origin=$_POST["origin"] $file="test.txt"; $open=fopen($file,"a"); if($open){ fwrite($open, $entry); fclos...

Multidimentional Vector in AS3

How can I initialise two-dimentional typed Vector is AS3? Now I can get working only this: private var _mainArray : Array = new Array( MyConst.DIMENTION ); public function MyArray() { for ( var i : int = 0; i < MyConst.DIMENTION; i++ ) { _mainArray[ i ] = new Vector.<int>( MyConst.DIMENTION ); } } ... _mainArray[...

Why do I need to cast before a method of an item of a NSArray can be called?

I am fairly new to Objective-C. Currently porting my own library from C#/Java to objective C. I now run into a very strange problem for me. I have a NSArray with several Note objects. I want to transpose on of these notes: //Note.h - (Note *) transpose: (int) semitones; //Main NSArray *notes = [get it from somewhere]; Note *tra...

How to rotate a matrix 90 degrees without using any extra space?

By saying 90 degrees i mean to say if: A = {1,2,3, 4,5,6, 7,8,9} then after 90 degree rotation A becomes: A = {7,4,1, 8,5,2, 9,6,3} ...

Is alloca completely replaceable?

I've read quite a few places that alloca is obsolete and should not be used and Variable Length Arrays should be used instead. My question is this: Is alloca completely replaceable by variable length arrays? In my particular instance I have something that looks like this: typedef struct { int *value; size_t size; } some_typ...

PHP $_POST print variable name along with value

I have a POST in PHP for which I won't always know the names of the variable fields I will be processing. I have a function that will loop through the values (however I would also like to capture the variable name that goes with it.) foreach ($_POST as $entry) { print $entry . "<br>"; } Once I figure out how to grab the variable...

Resolve Array with Ninject

In Ninject there's automatic implicit self-binding for concrete types. So without further configuration I can resolve every type in my application, like: Foo foo = Kernel.Get(typeof(Foo)); Now if I need an Array of Foo, how would I do that? Foo[] foos = Kernel.Get(typeof(Foo[])); // does not work EDIT: For clarification, here is, ...

Multidimential array into string

I have a result set from a DB that returns the following array.... how do I implode this into a comma delimited string? Thanks! Array ( [0] => Array ( [user_id] => 2 ) [1] => Array ( [user_id] => 5 ) [2] => Array ( [user_id] => 11 ) ) ...

Populate drop down list from array using JQuery

Assuming I have this array: Array( [0] => Array( [Brand] => 'Toyota', [Model] => 'Camry', [Color] => 'Red', [Year] => 2002 ) [1] => Array( [brand] => 'Nissan', [Model] => 'Skyline', [Color] => '...