arrays

Capture multiple check box selection JSP Parameters

I found this post that shows how to pass multiple check box selections to another JSP page, but it's not working for me. When I try to get the selected values I get: checked boxes: [Ljava.lang.String;@3f3fbd Here are my two pages (be gentle, this is my first attempt at JSP!) createSHAREfile.jsp basically runs a query to find all the ...

array_unique for objects?

Hi! Is there any method like the array_unique for objects? I have a bunch of arrays with 'Role' objects that I merge, and then I want to take out the duplicates :) Thanks ...

Variable length (Dynamic) Arrays in Java

I was wondering how to initialise an integer array such that it's size and values change through out the execution of my program, any suggestions? ...

perl to php translation

How do you translate this perl subroutine into a PHP function? sub disagreement { my $disagreement = 0; my %aggregate = () ; foreach my $item (@_) {$aggregate{$item}++} foreach my $cat_a (keys %aggregate) { foreach my $cat_b (keys %aggregate) { if ($cat_a != $cat_b) {$disagreement += $aggregate{$cat_a} * $aggregate{$ca...

How do I sort a multidimensional array by one of the fields of the inner array in PHP?

Suppose I have an array that mimics a dayabase table. Each array element reporesents a row and within each row is another array that contains the field names and values. Array ( [0] => Array ( [name] => Sony TV [price] => 600.00 ) [1] => Array ( [name] => LG TV ...

How to sort some values from an array in a controller in Rails?

I've got a links array that I'm saving to a database. The problem is that the records aren't saved in the order of the array ie links[1] is saved before links[2] and so on... This is a example from the view file: <p> <label for="links_9_label">Label</label> <input id="links_9_name" name="links[9][name]" size="30" type="text" /> <...

Why can't I create an array with size determined by a global variable?

Why does the array a not get initialized by global variable size? #include<stdio.h> int size=5; int main() { int a[size]={1,2,3,4,5}; printf("%d",a[0]); return 0; } The compilation error is shown as "variable-sized object may not be initialized". According to me the array should get initialized by size. and what would be...

How do I generate an array from a string representation of that array?

I want to generate the array $result_array. There is no error at the page, but not works! that not works ! //BOF: Result Array $result_array = ''; $result_array .= '"messages" => "' . $errors .'",'; $result_array .= '"this_addr_type" => "' . (int)$_REQUEST['edit'] .'",'; if (ACCOUNT_GENDER == 'true') { $result_array .= '"gender_mal...

Project Euler 7 Scala Problem

I was trying to solve Project Euler problem number 7 using scala 2.8 First solution implemented by me takes ~8 seconds def problem_7:Int = { var num = 17; var primes = new ArrayBuffer[Int](); primes += 2 primes += 3 primes += 5 primes += 7 primes += 11 primes += 13 while (primes.size < 10001){ ...

how to solve array_walk error

This is my codes and I got an error: require_once(IPT_DIR."config.php"); if ($trackip == 1) { $ipaddr = $_SERVER["REMOTE_ADDR"] ; $hostnm = gethostbyaddr("$ipaddr"); $exclude_me=false; array_walk($exclude_ips, 'exclude_ip'); if(!$exclude_me) array_walk($exclude_hosts, 'exclude_host'); if (!$ex...

PHP: visual difference between 2 arrays

I've these arrays: <?php // New $array1 = array( array( 'g_id' => '1', 'g_title' => 'Root Admin', 'g_perm_id' => '1', 'g_bitoptions' => '0' ), array( 'g_id' => '2', 'g_title' => 'Member', 'g_perm_id' => '2', 'g_bitoptions' => '32' ), array( 'g_i...

flexible length struct array inside another struct using C

Hi I am trying to use C to implement a simple struct: 2 boxes, each contains different number of particles; the exact number of particles are passed in main(). I wrote the following code: typedef struct Particle{ float x; float y; float vx; float vy; }Particle; typedef struct Box{ Particle p[]; }Box; void make_box...

Array::include? on ActiveRecord collection not calling op== ?

Given a collection of named Foos from ActiveRecord, why does Array#include? not seem to call Foo.== but yet index does? class Foo < ActiveRecord::Base def ==(s) self.name == s end end class Bar < ActiveRecord::Base has_many :foos end bar.foos << Foo.new( :name => 'hmm' ) bar.foos.all.include?('hmm') # does select all from ...

Flex DataGridColumn with array of objects as data provider

I have a datagrid that uses an array of objects as the data provider. The objects are essentially key/value pairs: { foo:"something"} { bar:"hello"} { caca:"lorem"} The datagrid has 2 columns. The first column is the key and the second column is the value. Right now my grid looks like: ...

How do you make a 2-d array in Matlab?

I want to make a 2D array dij(i and j are subscripts). I want to be able to do dij = di,j-1+(di,j-1 - di-1,dj-1)/(4^j-1) My idea for this it to make to 1D arrays and then combine them into a 2D array. Is there an easier way to do this? ...

c# array vs generic list

Hi, i basically want to know the differences or advantages in using a generic list instead of an array in the below mentioned scenario Class Employee { private _empName; Public EmpName { get{return _empName;} set{_empName = value;} } } 1. Employee[] emp 2. List<Employee> emp can anyone please tell me the advantages or disadvan...

Filter some words

I want to filter some reserved word on my title form. $adtitle = sanitize($_POST['title']); $ignore = array('sale','buy','rent'); if(in_array($adtitle, $ignore)) { $_SESSION['ignore_error'] = '<strong>'.$adtitle.'</strong> cannot be use as your title'; header('Location:/submit/'); exit; How to make something like this. If user type C...

Java: Preventing array going out of bounds.

I'm working on a game of checkers, if you want to read more about you can view it here; http://minnie.tuhs.org/I2P/Assessment/assig2.html When I am doing my test to see if the player is able to get to a certain square on the grid (i.e. +1 +1, +1 -1 .etc) from it's current location, I get an java.lang.ArrayIndexOutOfBoundsException error...

PHP: Count-IF for Arrays

Hi All, What would be the most efficient way of counting the number of times a value appears inside an array? Example Array ('apple','apple','banana','banana','kiwi') Ultimately I want a function to spit out the percentages for charting purposes (e.g. apple = 40%, banana = 40%, kiwi = 20%) ...

PHP 5 functioning returning an array- interaction without assignment?

I'm wondering if this kind of thing will ever be possible in PHP (and whether it already is and I'm just missing something...) <?php function test() { return array( 'id'=>10, 'name'=>'John' ); } echo 'Your name is: '.test()['name']; ?> I'd really like to be able to use returned arrays directly instead of first assigning them ...