arrays

php array pass by reference - assigning a duplicate value for the key gets discarded

Hi, I am sending a reference of an array variable which is initially empty. In the called function the array gets populated. function one() { $ret = array(); two($ret); pri nt_r($ret); } function two(&$res) { foreach($a as $b) { $id = $b->getid(); $txt = $b->gettxt(); $res[$id] = $txt; ...

how to put a limit on a while mysql_array?

//check which faction members are online $sql = mysql_query("SELECT * FROM ".TBL_ACTIVE_USERS." WHERE faction=$userfaction_id ORDER BY timestamp DESC,username"); //no '' around var as it is an integer, so php doesn't expeect it to be string $numrows = mysql_numrows($sql);//gets number of members online if($numrows == 1){ echo 'You are t...

Rails simple constants and select options.

I have a simple constant called "subjects" in my model Inquire.rb and I like to know if there is a simple way to use the position in the Ruby array rather than making a hash from it with ids or some more complicated array. Can I do this? i.e. instead of to_s as it currently does for the value in the select, I would want an integer indi...

Calculate the sum of matrices in a list or a 3D array

Given a list (length = n) of 2x2 matrices, how do I calculate the sum of all those matrices (and get a 2x2 matrix) ? How can I do it, if instead of a list I have those matrices in a (2 x 2 x n) dimensional array ? ...

Find the largest value smaller than x in a sorted array

Suppose I have a sorted array of integers int[], and I want to search the closest smaller value to some input number. for example if the array contains (1) , (23), (57) , (59), (120) and the input is 109, the output should be 59. I am just trying to see suggestions and compare to the approaches I already have. ...

PHP's in_array vs. MySQL SELECT

I need to check if some integer value is already in my database (which is growing all the time). And it should be done several thousand times in one script. I'm considering two alternatives: Read all those numbers from MySQL database into PHP array and every time I need to check it, use in_array function. Every time I need to check the...

The simplest question: extract values from array

So this is an example: Array ( [0] => Array ( [title] => Title_1 [checkout] => 1 [no_gateway] => 0 ) [1] => Array ( [title] => Title_2 [checkout] => 1 [no_gateway] => 1 ) [2] => Array ( [title] => Title_3 [checkout] => 0 [no_gateway] => 0 ) [3] => Array ( [title] => Title_4 [checkout] => 1 [no_gateway] => 1 ) [4] => Array ( [title] =>...

Send and Recive an array with jQuery Ajax

I want to send an array from main.html to test.php file and receive an other array from test.php , but it does not work.plz help me! main.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; <html xmlns="http://www.w3.org/1999/xhtml"&gt; <head> <title>Unti...

php - map table row with a href link dynamically

I have an array which i use to dynamically create a table. I have a name=value pair (Server=server.alias) which values are being extracted and would like to make it hyperlinked to another webpage. What I need help is figuring out the code to map the alias name with a specific href link which I think I will have to hard code. The href li...

median and max for an array in php

I am trying to set lower limit and upper limit for an array. The lower limit is always constant, which is 0 but i want the upper limit to be varying based on the array values. some times the array values are 1,2,3,4,5 and sometimes the array values are 100,200,300,400,500 and sometimes in thousands as well. So i do not want to set a co...

Javascript implementation question: how to make this function display values.

Please forgive me, but I do know js basics and how to write/call a basic function, but in this case I'm trying to match an alpha sorted list of categories from the DB to match against my set (non-alpha) order of said categories as specified below (this is code suggested for use by another user on a question I asked about how to map the o...

Error when adding value to array

hey guys, when i run: with open('file00.txt') as f00: for line in f00: farr=array.append(float(line)) print "farr= ",farr i get: farr=array.append(float(line)) AttributeError: 'module' object has no attribute 'append' does anyone know why I get this? do I have to import something? am I doing it compl...

Inside a structure how can I define an array (dynamic) of structures with the same type as the structure itself.

The objective is to build a "infinite" tree using dynamic arrays. items[3] - MENUITEM - items[2] - MENUITEM -items[0] - MENUITEM - items[0] - MENUITEM - items[0] - MENUITEM - items[2] - MENUITEM - items[0] - MENUITEM - items[0] I define the structure: typedef struct MENUITEM { char id...

How do I create an associate array in jquery and send it via ajax to get parsed with php?

How would I make an associative array (or some comparable alternative) in jQuery AND send that array via ajax to a php page so that I can use php to handle it? Something like this... // jQuery if($something == true) { data[alt] = $(this).attr('alt'); data[src] = $(this).attr('src'); else if ($something == "something else") { ...

find a minimum value in an array of floats

how would one go about finding the minimum value in an array of 100 floats in python? I have tried minindex=darr.argmin() and print darr[minindex] with import numpy (darr is the name of the array) but i get: minindex=darr.argmin() AttributeError: 'list' object has no attribute 'argmin' what might be the problem? is there a better alte...

erase whole array Python

Hey guys, how would you erase a whole array, as in it has no items. I want to do this so I could store new values (a new set of 100 floats) into it and find the minimum. Right now my program is reading the minimum from sets before I think because it is appending itself with the previous set still in there (i use .append by the way). ...

find value of forloop at which event occurred Python

hey guys, this is very confusing... i am trying to find the minimum of an array by: for xpre in range(100): #used pre because I am using vapor pressures with some x molarity xvalue=xarray[xpre] for ppre in range(100): #same as xpre but vapor pressures for pure water, p pvalue=parray[p] d=math...

decoding and encoding array in Objective-C

Hello, Can i decode and encode an array in ths way?? NSMutableArray *arr; -(void)encodeWithCoder:(NSCoder*)coder { [coder encodeInt:arr forKey:@"Array"]; } -(id)initWithCoder:(NSCoder*)decoder { NSMutableArray array; array = [[decoder decodeIntForKey:@"Array"]copy]; return self; } ...

Javascript arrays question

Is var myCars=new Array("Saab","Volvo","BMW"); and var myCars=["Saab","Volvo","BMW"]; exactly the same ? ...

How to add up a row of values in an array and move to the previous key PHP

Hello, I would like the value that has an o in the following example to be added to the key before the first key that has a value with an o in the array. Like this: $arr = array( 0 => 'apple', 1 => 'pear', 2 => 'orange', 3 => 'octopus', 4 => 'pineapple' ) $arr = array( 0 => 'apple', 1 => 'pearorangeoctopus', 2 => 'Pineapple' ) But ...