Search Results

Search found 15239 results on 610 pages for 'array population'.

Page 58/610 | < Previous Page | 54 55 56 57 58 59 60 61 62 63 64 65  | Next Page >

  • Assign to an array and replace emerged nil values

    - by Tobias
    Greetings! When assigning a value to an array as in the following, how could I replace the nils by 0? array = [1,2,3] array[10] = 2 array # => [1, 2, 3, nil, nil, nil, nil, nil, nil, nil, 2] If not possible when assigning, how would I do it the best way afterwards? I thought of array.map { |e| e.nil? ? 0 : e }, but well… Thanks!

    Read the article

  • convert object to array

    - by zahir hussain
    <?php print_r($response->response->docs); ?> display the following Array ( [0] => Object ( [_fields:private] => Array ( [id]=>9093 [name]=>zahir) Object ( [_fields:private] => Array ( [id]=>9094 [name]=>hussain)..) how to change the object to array... i want the following Array([0]=>([id]=>9093 [name]=>zahir) [1]=>([id]=>9094 [name]=>hussain)...) can i do? no one can answer....

    Read the article

  • Algorithm: efficient way to remove duplicate integers from an array

    - by ejel
    I got this problem from an interview with Microsoft. Given an array of random integers, write an algorithm in C that removes duplicated numbers and return the unique numbers in the original array. E.g Input: {4, 8, 4, 1, 1, 2, 9} Output: {4, 8, 1, 2, 9, ?, ?} One caveat is that the expected algorithm should not required the array to be sorted first. And when an element has been removed, the following elements must be shifted forward as well. Anyway, value of elements at the tail of the array where elements were shifted forward are negligible. Update: The result must be returned in the original array and helper data structure (e.g. hashtable) should not be used. However, I guess order preservation is not necessary. Update2: For those who wonder why these impractical constraints, this was an interview question and all these constraints are discussed during the thinking process to see how I can come up with different ideas.

    Read the article

  • PostgreSQL JOIN with array type with array elements order, how to implement?

    - by Adiasz
    Hello I have two tables in database: CREATE TABLE items( id SERIAL PRIMARy KEY, ... some other fields ); This table contains come data row with unique ID. CREATE TABLE some_choosen_data_in_order( id SERIAL PRIMARy KEY, id_items INTEGER[], ); This table contains array type field. Each row contains values of IDs from table "items" in specyfic order. For example: {2,4,233,5}. Now, I want to get data from table "items" for choosen row from table "some_choosen_data_in_order" with order for elements in array type. The my attempt is JOIN: SELECT I.* FROM items AS I JOIN some_choosen_data_in_order AS S ON I.id = ANY(S.id_items) WHERE S.id = ? Second attempt was subquery like: SELECT I.* FROM items AS I WHERE I.id = ANY (ARRAY[SELECT S.id_items FROM some_choosen_data_in_order WHERE id = ?]) But none of them keep IDs order in array field. Could You help me, how to get data from "items" table with correspond with array IDs order from "some_choosen_data_in_order" table for specyfic row?

    Read the article

  • Copy one jagged array ontop of another.

    - by George Johnston
    How could I accomplish copying one jagged array to another? For instance, I have a 5x7 array of: 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0 and a 4x3 array of: 0,1,1,0 1,1,1,1 0,1,1,0 I would like to be able to specify a specific start point such as (1,1) on my all zero array, and copy my second array ontop of it so I would have a result such as: 0, 0, 0, 0, 0, 0, 0 0, 0, 1, 1, 0, 0, 0 0, 1, 1, 1, 1, 0, 0 0, 0, 1, 1, 0, 0, 0 0, 0, 0, 0, 0, 0, 0 What would be the best way to do this?

    Read the article

  • Convert a generic list to an array

    - by Freewind
    I have searched for this, but unfortunately, I don't get the correct answer. class Helper { public static <T> T[] toArray(List<T> list) { T[] array = (T[]) new Object[list.size()]; for (int i = 0; i < list.size(); i++) { array[i] = list.get(i); } return array; } } Test it: public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("abc"); String[] array = toArray(list); System.out.println(array); } But there is an error thrown: Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String; at test.Helper.main(Helper.java:30) How to solve this?

    Read the article

  • getting a date array from a mysql database?

    - by user296516
    Hi guys, I have a database with date field is this format "2010.06.11. | 10:26 13" What is need is a php array that would hold all the different dates, .i.e. array[0] = "2010.06.09." array[1] = "2010.06.10." array[2] = "2010.06.11." Currently I am doing it by selecting the whole table, then looping through the result and adding the date substr to an array if it is not already there. But maybe there is a faster way? Thanks.

    Read the article

  • Displaying Array in Select - FORM API Drupal

    - by Krishma
    Hi: I want to add key(type_id) and value(type_description) to select in drupal form API $result_x-product_types-RPMProductType is array result from Database :- array(4) { [0]= object(stdClass)#18 (2) { ["type_description"]= string(10) "Calendered" ["type_id"]= int(1) } [1]= object(stdClass)#19 (2) { ["type_description"]= string(8) "Extruded" ["type_id"]= int(2) } [2]= object(stdClass)#20 (2) { ["type_description"]= string(6) "Molded" ["type_id"]= int(3) } [3]= object(stdClass)#21 (2) { ["type_description"]= string(5) "Other" ["type_id"]= int(4) } } foreach ($result_x-product_types-RPMProductType as $data) { $form['manufacturer_add_new_sales']['product_type'] = array( '#type' = 'select', '#title' = t('Product Type'), '#options'=array($data-type_id=$data-type_description), ); } When do so I am getting only last value i.e Other. How to correctly loop to bind Select to display all the array Key - Values. Thank you in advance.

    Read the article

  • type of an array

    - by Tim
    Hi, when I need to pass an array to a function, it seems all the following declarations of the function will work void f(int arr[]) void f(int arr[4]) // is this one correct? for this: int a[]={1,2,3,4}; f(a); But when I assign an array to another array, it fails int a[]={1,2,3,4}; int b[4] = a; // error: array must be initialized with a brace-enclosed initializer So why an array passed as an argument of a function is okay, but used on the rhs of simple assignment is wrong? Thanks!

    Read the article

  • Writing from an array to a file bash and new lines

    - by S1syphus
    I'm trying to write a script the generates a template file for Pashua (a perl script for creating GUI on osx) I want to crate an instance for each item in the array, so the ideal output would be: AB1.type = openbrowser AB1.label = Choose a master playlist file AB1.width=310 AB1.tooltip = Blabla filesystem browser AB2.type = openbrowser AB2.label = Choose a master playlist file AB2.width=310 AB2.tooltip = Blabla filesystem browser ...and so on for the rest of the array: What I am using to write to the text file at the moment is: count=1 saveIFS="$IFS" IFS=$'\n' array=($(<TEST.txt)) IFS="$saveIFS" for i in "${array[@]}"; do declare AD$count="$i"; ((count++)); done for i in "${array[@]}"; do echo "AD$count".type = openbrowser "AD$count".label = Choose a master playlist file \n "AD$count".width=310 \n "AD$count".tooltip = Blabla filesystem browser \n" >> long.txt; done However \n doesn't produce a newline in the text file, and I am pretty sure there is a alot nicer way todo this, ideas?

    Read the article

  • How to pass an array in AS3 to an array in php?

    - by luiz
    Hello friends, I have the following array as3 example: var arrayDefinitionsargsAmfPhp:Array = new Array(); arrayDefinitionsargsAmfPhp['tabela'] = "controls"; arrayDefinitionsargsAmfPhp['width'] = "100"; sending him to the remote object for php, example: async = bridge.getOperation(amfphpFunction).send(arrayDefinitionsargsAmfPhp); In php I try to get the array like this: function retornamenu($tableInBd) { $arr = array($tableInBd); $tableInBdname = $arr['tabela']; $widthInBdname = $arr['width']; But unfortunately these variables $tableInBdname and $widthInBdname not come to php, can someone help me with an example? Thank already

    Read the article

  • 'Array of arrays' in matlab?

    - by waitinforatrain
    Hey, having a wee bit of trouble. Trying to assign a variable length 1d array to different values of an array, e.g. a(1) = [1, 0.13,0.52,0.3]; a(2) = [1, 0, .268]; However, I get the error: ??? In an assignment A(I) = B, the number of elements in B and I must be the same. Error in ==> lab2 at 15 a(1) = [1, 0.13,0.52,0.3]; I presume this means that it's expecting a scalar value instead of an array. Does anybody know how to assign the array to this value? I'd rather not define it directly as a 2d array as it is for are doing solutions to different problems in a loop Edit: Got it! a(1,1:4) = [1, 0.13,0.52,0.3]; a(2,1:3) = [1, 0, .268];

    Read the article

  • crazy things with PHP array...

    - by user296516
    Hi, A very strange thing, I have an array where element 7 is '[1000137d]', but when I try to compare it by using if ( $array[7] == '[1000137d]' ) it will return a negative. echo $array[7]; echo '<br>'; echo '[1000137d]'; echo '<br>'; echo md5($array[7]); echo '<br>'; echo md5('[1000137d]'); this code would echo out: [1000137d] [1000137d] ca9983334e720042e3a6cbb1dd6b7fd2 3b1c21e661bd7d38deda1f4a45eaa23b as you can see $array[7] is identical to [1000137d], yet their md5's differ. what do you think might be the problem? Thanks!

    Read the article

  • Get from associative array only that elements which keys are specified

    - by hsz
    Hello ! It's late and I know it is a very simple question but right now I do not have an idea and deadline is near.. I've got two arrays: $array1 = array( 'a' => 'asdasd', 'b' => 'gtrgrtg', 'c' => 'fwefwefw', 'd' => 'trhrtgr', ); $array2 = array( 'b', 'c' ); What was the name of function to get a part of assoc array by keys from the second array ? $result = array( 'b' => 'gtrgrtg', 'c' => 'fwefwefw', ); Thanks !

    Read the article

  • Unix tree convert to recursive php array

    - by Fordnox
    I have a response from remote server like this: /home/computer/Downloads |-- /home/computer/Downloads/Apple | `-- /home/computer/Downloads/Apple/Pad |-- /home/computer/Downloads/Empty_Folder `-- /home/computer/Downloads/Subfolder |-- /home/computer/Downloads/Subfolder/Empty `-- /home/computer/Downloads/Subfolder/SubSubFolder `-- /home/computer/Downloads/Subfolder/SubSubFolder/Test this is the output for command computer@athome:$ tree -df --noreport -L 5 /home/computer/Downloads/ I would like to parse this string to recursive php array or object, something like this. I would show only part of result to get the idea. array( 'title' => '/home/computer/Downloads', 'children' => array( 0 => array( 'title' => '/home/computer/Downloads/Apple', 'children' => array( ... ) ) ); Response from server can change according to scanned directory. Can someone help me write this function. Please note that this is response from remote server and php functions can not scan any remote dir.

    Read the article

  • Arrays- Square root of an Array and printing the result JAVA

    - by roger34
    Hello, The title says it all, really. I'm trying to get an array of (9) numbers squared then printed but I keep coming back with only one result - the number of numbers in the array squared- obviously not what I want. Thanks for any help. Ok, here is my terrible code so far. Trying to pass it to a method as well. public static void main ( String args[] ) { double[] nums = {126, 12.939, 795, 320.16, 110, 34.7676, 7773, 67, 567, 323}; System.out.println ("Square root is " +square); square(nums); } public static double square (double [] array) { double result; for( double i = 0; i < array.length ; i++ ) result = Math.sqrt(array[i]); return result; } }

    Read the article

  • str_replace() with associative array

    - by Qiao
    You can use arrays with str_replace(): $array_from = array ('from1', 'from2'); $array_to = array ('to1', 'to2'); $text = str_replace ($array_from, $array_to, $text); But what if you have associative array? $array_from_to = array ( 'from1' => 'to1'; 'from2' => 'to2'; ); How can you use it with str_replace()? Speed matters - array is big enough.

    Read the article

  • Zend framework multiple Validators in an array

    - by iSenne
    Hello everybody I want to create a form in Zend framework. I am using the code below for a field: $this->addElement('text', 'username', array( 'label' => 'Username:', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array( 'alnum' ) )); This works. But now I also want to add a new validator. In this case StrinLength $element->addValidator('StringLength', false, array(6, 20)); How can I add this validator in the array I already have? Tnx in advanced

    Read the article

  • I want to move 1 array to another in C#

    - by George
    Hi, This is just a quick question in C#. I have a scenario where I am working with several devices that all have slightly different data to work with. When I work out which device I am using, I want to set up a common array to use throughout the code, say arrayCommon. So I want to move the info from device1 to the common array. Do I have to do this in a loop for each occurance in the array or can u move the whole array into the common array, as you could in Cobol all those years ago ? Thanks, George.

    Read the article

  • Excel VBA pass array of arrays to a function

    - by user429400
    I have one function that creates an array of arrays, and one function that should get the resulting array and write it to the spreadsheet. I don't find the syntax which will allow me to pass the array of arrays to the second function... Could you please help? Here is my code: The function that creates the array of arrays: Function GetCellDetails(dict1 As Dictionary, dict2 As Dictionary) As Variant Dim arr1, arr2 arr1 = dict1.Items arr2 = dict2.Items GetCellDetails = Array(arr1, arr2) End Function the function that writes it to the spreadsheet: Sub WriteCellDataToMemory(arr As Variant, day As Integer, cellId As Integer, nCells As Integer) row = CellIdToMemRow(cellId, nCells) col = DayToMemCol(day) arrSize = UBound(arr, 2) Range(Cells(row, col), Cells(row + arrSize , col + 2)) = Application.Transpose(arr) End Sub The code that calls the functions: Dim CellDetails CellDetails = GetCellDetails(dict1, dict2) WriteCellDataToMemory CellDetails, day, cellId, nCells Thanks, Li

    Read the article

  • Array of pointers in Objective-C using NSArray

    - by Amir
    Hello, I am writting program for my iphone and have a qestion. lets say i have class named my_obj class my_obj { NSString *name; NSinteger *id; NSinteger *foo; NSString *boo; } now i allocate 100 objects from type my_obj and insert them to array from type NSArray. then i want to sort the Array in two different ways. one by the name and the second by the id. i want to allocate another two arrays from type NSArray *arraySortByName *arraySortById what i need to do if i just want the sorted arrays to be referenced to the original array so i will get two sorted arrays that point to the original array (that didnt changed!) i other word i dont want to allocate another 100 objects to each sorted array.

    Read the article

  • Array in Bash Not Found

    - by Waffle
    I am trying to declare an array in bash, but when the code is run it says it cannot find the array. I have tried to write out the declaration of the array in several different ways, but it seems no matter how I try to declare it I cannot get it to work. I originally tried to declare it as such: candidate[1]= 0 candidate[2]= 0 candidate[3]= 0 The error messages that are returned are: votecalculation.sh: 13: candidate[1]=: not found votecalculation.sh: 14: candidate[2]=: not found votecalculation.sh: 15: candidate[3]=: not found After this I tried another solution I found online: ARRAY=( 'can1' 'can2' 'can3' ) When that is used it returns this error: votecalculation.sh: 12: Syntax error: "(" unexpected I am new to Bash and am getting really confused about arrays. Is there some specific way I need to declare an array or am I just going about it completely wrong?

    Read the article

  • str_replace() with two-dimensional array

    - by Qiao
    You can use arrays with str_replace(): $array_from = array ('from1', 'from2'); $array_to = array ('to1', 'to2'); $text = str_replace ($array_from, $array_to, $text); But what if you have two-dimensional array? $array_from_to = array ( 'from1' => 'to1'; 'from2' => 'to2'; ); How can you use it with str_replace()? Speed matters - array is big enough.

    Read the article

  • C# - Dictionary with generic array as value

    - by alhazen
    In my class, I want to use a dictionary with the following declaration: Dictionary<string, T[]> Since the operations of my class are exactly the same for all generic types, I do not wish to define my class as generic (which means I would have to create a separate instance of my class for each generic type I insert into the dictionary ?). One alternative I'm attempting is to use Dictionary<string, object> instead: public void Add<T>(string str, T value) { // Assuming key already exists var array = (T[]) dictionary[str]; array[0] = value; } However, when iterating over the dictionary, how do I cast the object value back to an array ? foreach(string strKey in dictionary.Keys) { var array = (T[]) dictionary[strKey]; // How to cast here ? //... array[0] = default(T); } Thanks.

    Read the article

  • packing fields of a class into a byte array in c#

    - by alex
    Hi all: I am trying to create a fast way to convert c# classes into byte array. I thought of serializing the class directly to a byte array using an example I found: // Convert an object to a byte array private byte[] ObjectToByteArray(Object obj) { if(obj == null) return null; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, obj); return ms.ToArray(); } But the byte array I got contains some other information that are not related to the fields in the class. I guess it is also converting the Properties of the class. Is there a way to serialize only the fields of the class to a byte array? Thanks

    Read the article

< Previous Page | 54 55 56 57 58 59 60 61 62 63 64 65  | Next Page >