Search Results

Search found 15104 results on 605 pages for 'multidimensional array'.

Page 11/605 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Can I assign array size using NSMutableArray?

    - by Tattat
    I used to be a Java Programmer, which the array need to declare the very first time, like this: int[] anArray; // declares an array of integers anArray = new int[10]; // allocates memory for 10 integers I don't know whether the Objective C , NSMutableArray also give me this ability or not. Actually, I want to make a 10*10 array. thz in advance.

    Read the article

  • Sorting an array based on its value

    - by MaxerDude
    I have an Array, Sample: $array { [0] { [something]=1; [something2]=2; } [1] { [something]=2; [something2]=4; } [2] { [something]=5; [something2]=2; } } I want to order the array based on the key something; So it will look like: $array { [0] { [something]=5; [something2]=2; } [1] { [something]=2; [something2]=4; } [2] { [something]=1; [something2]=2; } }

    Read the article

  • Dynamical array of strings in C

    - by Ir0nm
    I'm trying to make array of strings, I have function rLine which reads line from stdin, each inputted line I need to save in array, but I don't have any idea about number of inputted string lines. So I need to dynamically increase array size to store them, I wrote such code: char *res[2], *old = res; while( 1 ){ line = rLine( stdin ), len = strlen( line ); res[row] = (char*)malloc( len + 1); strcpy( res[row++], line); res = (char**) realloc( res, row ); /* adding 1 more row, not sure adding size row? */ if ( /*some cond*/ ) break; } But this code doesn't seem to work, how correctly declare array and increase it size?

    Read the article

  • ruby sortby 3rd element in a multidimential array npot working properly

    - by Steven
    Hi, I'm using ruby to sort an array where each element in the array is another array. I have this: Data = Data.SortBy { |Info| info[3] } example data in this column: 3.1 2 5.65 -1 0.4 -9.43 -10.87 -2.3 It should sort this into: 5.65 3.1 2 0.4 -1 -2.3 -9.43 -10.87 But it comes out like this: 5.65 3.1 2 0.4 -1 -10.87 -2.3 -9.43 It's only comparing the first char of the float... not the whole number?

    Read the article

  • PHP 5.2 Function needed for GENERIC sorting of a recordset array

    - by donbriggs
    Somebody must have come up with a solution for this by now. We are using PHP 5.2. (Don't ask me why.) I wrote a PHP class to display a recordset as an HTML table/datagrid, and I wish to expand it so that we can sort the datagrid by whichever column the user selects. In the below example data, we may need to sort the recordset array by Name, Shirt, Assign, or Age fields. I will take care of the display part, I just need help with sorting the data array. As usual, I query a database to get a result, iterate throught he result, and put the records into an assciateiave array. So, we end up with an array of arrays. (See below.) I need to be able to sort by any column in the dataset. However, I will not know the column names at design time, nor will I know if the colums will be string or numeric values. I have seen a ton of solutions to this, but I have not seen a GOOD and GENERIC solution Can somebody please suggest a way that I can sort the recordset array that is GENERIC, and will work on any recordset? Again, I will not know the fields names or datatypes at design time. The array presented below is ONLY an example. UPDATE: Yes, I would love to have the database do the sorting, but that is just not going to happen. The queries that we are running are very complex. (I am not really querying a table of Star Trek characters.) They include joins, limits, and complex WHERE clauses. Writing a function to pick apart the SQL statement to add an ORDER BY is really not an option. Besides, sometimes we already have the array that is a result of the query, rather than the ability to run a new query. Array ( [0] => Array ( [name] => Kirk [shrit] => Gold [assign] => Bridge ) [1] => Array ( [name] => Spock [shrit] => Blue [assign] => Bridge ) [2] => Array ( [name] => Uhura [shrit] => Red [assign] => Bridge ) [3] => Array ( [name] => Scotty [shrit] => Red [assign] => Engineering ) [4] => Array ( [name] => McCoy [shrit] => Blue [assign] => Sick Bay ) )

    Read the article

  • PHP array help getting a value from the key

    - by sea_1987
    I have a variable that looks likes this, $rslt['expected_salary_level'] This returns a string similar to LEVEL_3, in another array that looks like this I have a set of salaries, Array ( [LEVEL_1] => Array ( [nice_name] => under &pound;10,000 [low] => 1 [high] => 10000 ) [LEVEL_2] => Array ( [nice_name] => &pound;10,000 - &pound;15,000 [low] => 10000 [high] => 15000 ) [LEVEL_3] => Array ( [nice_name] => &pound;15,000 - &pound;20,000 [low] => 15000 [high] => 20000 ) [LEVEL_4] => Array ( [nice_name] => &pound;20,000 - &pound;25,000 [low] => 20000 [high] => 25000 ) [LEVEL_5] => Array ( [nice_name] => &pound;25,000 - &pound;30,000 [low] => 25000 [high] => 30000 ) [LEVEL_6] => Array ( [nice_name] => &pound;30,000 - &pound;40,000 [low] => 30000 [high] => 40000 ) [LEVEL_7] => Array ( [nice_name] => &pound;40,000 - &pound;50,000 [low] => 40000 [high] => 50000 ) [LEVEL_8] => Array ( [nice_name] => &pound;50,000 - &pound;100,000 [low] => 50000 [high] => 100000 ) [LEVEL_9] => Array ( [nice_name] => &pound;100,000 or more [low] => 100000 [high] => 9999999 ) [LEVEL_VOLUNTARY] => Array ( [nice_name] => Voluntary [low] => [high] => ) [LEVEL_UNSPECIFIED] => Array ( [nice_name] => Not specified [low] => [high] => ) ) How do I get at the associated nice name?

    Read the article

  • copy array from one class to another class array

    - by shishir.bobby
    hi all, i hv an array ("array A", which contains 3 objects, fox ex, to,from,message) in class "A". and in class "B",i m having another array ("array B"),which fills tableview,of class "B" only. i need to fill tableview,with the values of class A's array (i.e array A,with the object values, to,from,message). how can i do it?? how to copy array from another class ? i hope i m clear with my question regards shishir

    Read the article

  • How to sort an array by some specific key?

    - by vinothkumar
    I have an array look like below. $array[0]['keyword'] = 'cricket '; $array[0]['noofhits'] = '26'; $array[0]['keyword'] = 'food '; $array[0]['noofhits'] = '17'; $array[0]['keyword'] = 'mypax'; $array[0]['noofhits'] = '22'; $array[0]['keyword'] = 'next'; $array[0]['noofhits'] = '22'; $array[0]['keyword'] = 'nextbutton'; $array[0]['noofhits'] = '22'; $array[0]['keyword'] = 'picture'; $array[0]['noofhits'] = '18'; I want to sort the array using the noofhits. How can I do? Advance Thanks for your advice.

    Read the article

  • How can we make a single dimension array to multidimensional Hierarchical ?

    - by Chetan sharma
    I have an single array of Hierarchical categories. Index of the array is the category_id like:: [8846] => Array ( [category_id] => 8846 [title] => Tsting two [description] => Tsting two [subtype] => categories [type] => object [level] => 2 [parent_category] => 8841 [tags] => new [name] => Tsting two ) each value has its parent_category value, I have around 500 elements in the array, what is the best way to make it. Process i followed: krsort categories array, so that all the child categories are at the beginning, then function makeHierarchical() { foreach($this->categories as $guid => $category) { if($category['level'] != 1) $this->multilevel_categories[$category['parent_category']][$guid] = $category; } } but this is not working, it does it only for first level. Can someone point out me the error.

    Read the article

  • How do I return the indices of a multidimensional array element in C?

    - by Eddy
    Say I have a 2D array of random boolean ones and zeroes called 'lattice', and I have a 1D array called 'list' which lists the addresses of all the zeroes in the 2D array. This is how the arrays are defined: define n 100 bool lattice[n][n]; bool *list[n*n]; After filling the lattice with ones and zeroes, I store the addresses of the zeroes in list: for(j = 0; j < n; j++) { for(i = 0; i < n; i++) { if(!lattice[i][j]) // if element = 0 { list[site_num] = &lattice[i][j]; // store address of zero site_num++; } } } How do I extract the x,y coordinates of each zero in the array? In other words, is there a way to return the indices of an array element through referring to its address?

    Read the article

  • php array_unique

    - by dotty
    HAy, i have an array Array( [0] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) [1] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) [2] => Array ( [0] => 33 [user_id] => 33 [1] => 8 [frame_id] => 8 ) [3] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) [4] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) ) As you can see key 0 is the same as 1,3 and 4. And key 2 is different from them all. When running the array_unique function on them, the only left is Array ( [0] => Array ( [0] => 33 [user_id] => 33 [1] => 3 [frame_id] => 3 ) ) any ideas why array_unique isn't working as expected?

    Read the article

  • Scala Array constructor?

    - by Lukasz Lew
    scala> val a = Array [Double] (10) a: Array[Double] = Array(10.0) scala> val a = new Array [Double] (10) a: Array[Double] = Array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) Why these two expressions have different semantics?

    Read the article

  • adding array values

    - by christian
    Array ( [0] => Array ( [datas] => Array ( [name] => lorem [id] => 1 [type] => t1 [due_type] => Q1 [t1] => 1 [t2] => 1 [t3] => 1 ) ) [1] => Array ( [datas] => Array ( [name] => lorem [id] => 1 [type] => t2 [due_type] => Q1 [t1] => 0 [t2] => 1 [t3] => 0 ) ) [2] => Array ( [datas] => Array ( [name] => name [id] => 2 [type] => t1 [due_type] => Q1 [t1] => 1 [t2] => 0 [t3] => 1 ) ) [3] => Array ( [datas] => Array ( [name] => name [id] => 2 [type] => t2 [due_type] => Q1 [t1] => 1 [t2] => 0 [t3] => 0 ) ) ) I want to add the values of each array according to its id, but I am having problem getting the values using these code: I want to compute the sum of all type according to each due_type and combining them into one array. $totals = array(); $i = -1; foreach($datas as $key => $row){ $i += 1; $items[$i] = $row; if (isset($totals[$items[$i]['datas']['id']])){ if($totals[$items[$i]['datas']['id']]['due_type'] == 'Q1'){ if($totals[$items[$i]['datas']['id']]['type'] == 't1'){ $t1+=$totals[$items[$i]['datas']['id']]['t1']; }elseif($totals[$items[$i]['datas']['id']]['type'] == 't2'){ $t2+=$totals[$items[$i]['datas']['id']]['t2']; }elseif($totals[$items[$i]['datas']['id']]['type'] == 't3'){ $t3+=$totals[$items[$i]['datas']['id']]['t3']; } $totals[$items[$i]['datas']['id']]['t1_total'] = $t1; $totals[$items[$i]['datas']['id']]['t2_total'] = $t2; } } else { $totals[$items[$i]['datas']['id']] = $row['datas']; $totals[$items[$i]['datas']['id']]['t1_total'] = $items[$i]['datas']['t1']; $totals[$items[$i]['datas']['id']]['t2_total'] = $items[$i]['datas']['t2']; } }

    Read the article

  • PHP compare two dimension array

    - by Jerry
    Hello guys I would like to know how to compare two two-dimension arrays value. First array Array 1 ( [0] => Array ( [0] => a ) [1] => Array ( [0] => b ) [2] => Array ( [0] => c ) } Second one Array 2 ( [0] => Array ( [0] => a ) [1] => Array ( [0] => d ) [2] => Array ( [0] => e ) } I need to know if my loop could compare the arrays to check the matched value. In my case, array1[0][0]=a matches array2[0][0]=a. If it matches, php will output some html. My foreach loop foreach ($array1 as $arrays){ foreach($arrays as $array){ //need to compare array2 here not sure how to do it. } } I would appreciate any helps. Thanks!

    Read the article

  • php - arrange array to display in score order

    - by Phil Jackson
    hi, i have wrote a script to produce an array of data but now want to display in order of score. The array outputs as follows; [display_name] => Array ( [0] => ACT_Web_Designs [1] => user1_design [2] => user2_design ) [proffesion] => Array ( [0] => Web Developer [1] => web developer [2] => Web Developer ) [score] => Array ( [0] => 15 [1] => 6 [2] => 15 ) [img] => Array ( [0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic [1] => [2] => ) so in a nutshell I am wanting it to be converted as follows; [display_name] => Array ( [0] => ACT_Web_Designs [1] => user2_design [2] => user1_design ) [proffesion] => Array ( [0] => Web Developer [1] => web developer [2] => Web Developer ) [score] => Array ( [0] => 15 [1] => 15 [2] => 6 ) [img] => Array ( [0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic [1] => [2] => ) I have been looking at asort() but cant get anything to work. any help would be much appreciated.

    Read the article

  • In C, as free() knows an array size, why isn't there a function that gets the array size? [closed]

    - by user354959
    Possible Duplicate: If free() knows the length of my array, why can’t I ask for it in my own code? Searching around (including here at stackoverflow), I got that malloc() allocates an array and also creates a header to control the array info. In this header, there's also the array size. free() use such information to know how to deallocate that array. So, if the array size info is "there" (somewhere in the memory), why there isn't a function that returns an array size, looking for this at the array header? Or am I missing something?

    Read the article

  • How to declare a 2D array of 2D array pointers and access them?

    - by vikramtheone
    Hi Guys, How can I declare an 2D array of 2D Pointers? And later access the individual array elements of the 2D arrays. Is my approach correct? void alloc_2D(int ***memory, unsigned int rows, unsigned int cols); int main() { int i, j; int **ptr; int **array[10][10]; for(i=0;i<10;i++) { for(j=0;j<10;j++) { alloc_2D(&ptr, 10, 10); array[i][j] = ptr; } } //After I do this, how can I access the 10 individual 2D arrays? return 0; } void alloc_2D(int ***memory, unsigned int rows, unsigned int cols) { int **ptr; *memory = NULL; ptr = malloc(rows * sizeof(int*)); if(ptr == NULL) { printf("\nERROR: Memory allocation failed!"); } else { int i; for(i = 0; i< rows; i++) { ptr[i] = malloc(cols * sizeof(float)); if(ptr[i]==NULL) { printf("\nERROR: Memory allocation failed!"); } } } *memory = ptr; }

    Read the article

  • Finding a list of indices from master array using secondary array with non-unique entries

    - by fideli
    I have a master array of length n of id numbers that apply to other analogous arrays with corresponding data for elements in my simulation that belong to those id numbers (e.g. data[id]). Were I to generate a list of id numbers of length m separately and need the information in the data array for those ids, what is the best method of getting a list of indices idx of the original array of ids in order to extract data[idx]? That is, given: a=numpy.array([1,3,4,5,6]) # master array b=numpy.array([3,4,3,6,4,1,5]) # secondary array I would like to generate idx=numpy.array([1,2,1,4,2,0,3]) The array a is typically in sequential order but it's not a requirement. Also, array b will most definitely have repeats and will not be in any order. My current method of doing this is: idx=numpy.array([numpy.where(a==bi)[0][0] for bi in b]) I timed it using the following test: a=(numpy.random.uniform(100,size=100)).astype('int') b=numpy.repeat(a,100) timeit method1(a,b) 10 loops, best of 3: 53.1 ms per loop Is there a better way of doing this?

    Read the article

  • Comment associative array in PHP Documentor

    - by Abenil
    Hey Guys, i hope someone can help me out on this one here. I use several associative arrays in my php application and i'm using to php documentor to comment my sources. I never really did specified comments for the arrays in an array, but now i need to do that and dont know how. $array = array('id' => 'test', 'class' => 'tester', 'options' => array('option1' => 1, 'option2' => 2)) So how do i comment this array in the correct way for @var and @param comments? I could do this like this, but dunno, if this is correct: @param string $array['id'] @param string $array['class'] @param int $array['options']['option1'] But how to this for the var part? I hope someone can lead me to the right direction. Thanks in advance for any help. Regards

    Read the article

  • Change index order in array (php)

    - by Trikks
    Hi Been kind of stuck on this one for a while now, so any help would be appreciated. I have one array (left) that contains a list of elements, the goal is to sort another arrays (right) keys with the values from the left array. The left array Array ( [0] => ID [1] => FirstName [2] => LastName [3] => Address ) The right array Array ( [0] => Array ( [FirstName] => Pim [Address] => Finland [LastName] => Svensson [ID] => 3 ) [1] => Array ( [FirstName] => Emil [Address] => Sweden [LastName] => Malm [ID] => 5 ) ) What I'm trying to accomplish would be similar to this Array ( [0] => Array ( [ID] => 3 [FirstName] => Pim [LastName] => Svensson [Address] => Finland ) Anyone? :) Oh, I'm running php 5.3, if it helps!

    Read the article

  • PHP modifying and combining array

    - by Industrial
    Hi everyone, I have a bit of an array headache going on. The function does what I want, but since I am not yet to well acquainted with PHP:s array/looping functions, so thereby my question is if there's any part of this function that could be improved from a performance-wise perspective? I tried to be as complete as possible in my descriptions in each stage of the functions which shortly described prefixes all keys in an array, fill up eventual empty/non-valid keys with '' and removes the prefixes before returning the array: $var = myFunction ( array('key1', 'key2', 'key3', '111') ); function myFunction ($keys) { $prefix = 'prefix_'; $keyCount = count($keys); // Prefix each key and remove old keys for($i=0;$i<$keyCount; $i++){ $keys[] = $prefix.$keys[$i]; unset($keys[$i]); } // output: array('prefix_key1', 'prefix_key2', 'prefix_key3', '111) // Get all keys from memcached. Only returns valid keys $items = $this->memcache->get($keys); // output: array('prefix_key1' => 'value1', 'prefix_key2' => 'value2', 'prefix_key3'=>'value3) // note: key 111 was not found in memcache. // Fill upp eventual keys that are not valid/empty from memcache $return = $items + array_fill_keys($keys, ''); // output: array('prefix_key1' => 'value1', 'prefix_key2' => 'value2', 'prefix_key3'=>'value3, 'prefix_111' => '') // Remove the prefixes for each result before returning array to application foreach ($return as $k => $v) { $expl = explode($prefix, $k); $return[$expl[1]] = $v; unset($return[$k]); } // output: array('key1' => 'value1', 'key2' => 'value2', 'key3'=>'value3, '111' => '') return $return; } Thanks a lot!

    Read the article

  • Is this 2D array initialization a bad idea?

    - by Brendan Long
    I have something I need a 2D array for, but for better cache performance, I'd rather have it actually be a normal array. Here's the idea I had but I don't know if it's a terrible idea: const int XWIDTH = 10, YWIDTH = 10; int main(){ int * tempInts = new int[XWIDTH * YWIDTH]; int ** ints = new int*[XWIDTH]; for(int i=0; i<XWIDTH; i++){ ints[i] = &tempInts[i*YWIDTH]; } // do things with ints delete[] ints[0]; delete[] ints; return 0; } So the idea is that instead of newing a bunch of arrays (and having them placed in different places in memory), I just point to an array I made all at once. The reason for the delete[] (int*) ints; is because I'm actually doing this in a class and it would save [trivial amounts of] memory to not save the original pointer. Just wondering if there's any reasons this is a horrible idea. Or if there's an easier/better way. The goal is to be able to access the array as ints[x][y] rather than ints[x*YWIDTH+y].

    Read the article

  • How to handle array element between int and Integer

    - by masato-san
    First, it is long post so if you need clarification please let me know. I'm new to Java and having difficulty deciding whether I should use int[] or Integer[]. I wrote a function that find odd_number from int[] array. public int[] find_odd(int[] arr) { int[] result = new int[arr.length]; for(int i=0; i<arr.length; i++) { if(arr[i] % 2 != 0) { //System.out.println(arr[i]); result[i] = arr[i]; } } return result; } Then, when I pass the int[] array consisting of some integer like below: int[] myArray = {-1, 0, 1, 2, 3}; int[] result = find_odd(myArray); The array "result" contains: 0, -1, 0, 1, 0, 3 Because in Java you have to define the size of array first, and empty int[] array element is 0 not null. So when I want to test the find_odd() function and expect the array to have odd numbers (which it does) only, it throws the error because the array also includes 0s representing "empty cell" as shown above. My test code: public void testFindOddPassValidIntArray() { int[] arr = {-2, -1, 0, 1, 3}; int[] result = findOddObj.find_odd(arr); //check if return array only contain odd number for(int i=0; i<result.length; i++) { if(result[i] != null) { assert is_odd(result[i]) : result[i]; } } } So, my question is should I use int[] array and add check for 0 element in my test like: if(result[i] != 0) { assert is_odd(result[i] : result[i] } But in this case, if find_odd() function is broken and returning 0 by miscalculation, I can't catch it because my test code would only assume that 0 is empty cell. OR should I use Integer[] array whose default is null? How do people deal with this kind of situation?

    Read the article

  • Nested foreach loops for associative array combinations

    - by JohnL
    I have an associative array as follows: $myarray = array('a'=>array(), 'b'=>array(), 'c'=>array(), 'd'=>array()); I want to be able to get all pairs of elements in the array. If it wasn't an associative array, I would use nested for loops, like: for($i=0; $i<count($myarray); $i++) { for($j=$i+1; $j<count($myarray); $j++) { do_something($myarray[$i], $myarray[$j]); } } I have looked at using foreach loops, but as the inner loop goes through ALL elements, some pairs are repeated. Is there a way to do this? Thanks!

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >