Search Results

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

Page 4/605 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Reverse alphabetic sort multidimensional PHP array maintain key

    - by useyourillusiontoo
    I'm dying here, any help would be great. I've got an array that I can sort a-z on the value of a specific key but cannot sort in reverse z-a. sample of my array which i'd like to sort by ProjectName (z-a): Array ( [0] => Array ( [count] => 1 [ProjectName] => bbcjob [Postcode] => 53.471922,-2.2996078 [Sector] => Public ) [1] => Array ( [count] => 1 [ProjectName] => commercial enterprise zone [Postcode] => 53.3742081,-1.4926439 [Sector] => Public ) [2] => Array ( [count] => 1 [ProjectName] => Monkeys eat chips [Postcode] => 51.5141492,-0.2271227 [Sector] => Private the desired results would be to maintain the entire array key - value structure but with the order: Monkeys eat chips Commericial enterprise zone bbcjob I hope this makes sense

    Read the article

  • Adding array to an object breaks the array

    - by DisgruntledGoat
    I have an array like this (output from print_r): Array ( [price] => 700.00 [room_prices] => Array ( [0] => [1] => [2] => [3] => [4] => ) [bills] => Array ( [0] => Gas ) ) I'm running a custom function to convert it to an object. Only the top-level should be converted, the sub-arrays should stay as arrays. The output comes out like this: stdClass Object ( [price] => 700.00 [room_prices] => Array ( [0] => Array ) [bills] => Array ( [0] => Array ) ) Here is my conversion function. All it does is set the value of each array member to an object: function array_to_object( $arr ) { $obj = new stdClass; if ( count($arr) == 0 ) return $obj; foreach ( $arr as $k=>$v ) $obj->$k = $v; return $obj; } I can't figure this out for the life of me!

    Read the article

  • How to sort a multidimensional array by a certain key?

    - by Eelke
    This should be really simple, but what is the way to go on this. I want to sort an multidimensional array by a key, like this: Array ( [0] => Array ( [iid] => 1 [invitee] => 174 [nid] => 324343 [showtime] => 2010-05-09 15:15:00 [location] => 13 [status] => 1 [created] => 2010-05-09 15:05:00 [updated] => 2010-05-09 16:24:00 ) [1] => Array ( [iid] => 1 [invitee] => 220 [nid] => 21232 [showtime] => 2010-05-09 15:15:00 [location] => 12 [status] => 0 [created] => 2010-05-10 18:11:00 [updated] => 2010-05-10 18:11:00 )) Say i want to sort this by [status], how would I achieve this? Thanks in advance!

    Read the article

  • Sorting a multidimensional array in objective-c

    - by Zen_silence
    Hello, I'm trying to sort a multidimensional array in objective-c i know that i can sort a single dimensional array using the line of code below: NSArray *sortedArray = [someArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; I can't seem to figure out how to sort a 2D array like the one below: ( ("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY"), ("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY"), ("SOME_URL", "SOME_STORY_TITLE", "SOME_CATEGORY") ); If someone could provide me code that would sort the array by SOME_CATEGORY it would be of great help to me. Thanks, Zen_Silence

    Read the article

  • Android java assigning 2d array to 3d array

    - by semajhan
    I'm running into problems trying to assign a 2d array to a 3d array, so I thought i'd ask a question about 3d and 2d arrays. Say I have a masterArray[][][] and wanted to put childArray1[][] and childArray2[][] into it. This is how I have done it and was wondering if that is the correct way of applying it: private int[][][] masterArray; private int[][] childArray1 = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 1, 0, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 1, 1, 1, 1, 1, 1, 0, 1}, {1, 0, 1, 1, 1, 1, 0, 1, 0, 1}, {1, 0, 1, 1, 0, 1, 0, 1, 0, 1}, {1, 0, 1, 1, 0, 1, 1, 1, 0, 1}, {1, 0, 1, 1, 1, 1, 1, 1, 0, 1}, {1, 0, 1, 1, 0, 1, 1, 1, 0, 1}, {1, 0, 1, 1, 0, 1, 8, 1, 0, 1}, {1, 0, 7, 1, 1, 1, 0, 1, 0, 1}, {1, 0, 1, 1, 1, 1, 0, 1, 0, 1}, {1, 0, 1, 1, 1, 1, 1, 1, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 9, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} }; private int[][] childArray2 = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, {1, 1, 1, 1, 7, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 0, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 9, 1, 1, 8, 0, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }; Ok, so in my init method I use these some methods to set the child arrays into the master array. What I was curious about was how this exactly works. I assumed the following: masterLevel = new int[MAX_LEVELS][MAP_WIDTH][MAP_HEIGHT]; for (int x = 0; x < MAP_WIDTH; x++) { for (int y = 0; y < MAP_HEIGHT; y++) { masterArray[currentLevel][x][y] = childArray1[x][y]; } } Would that work? In my application things aren't working so I picking out code that I am not 100% sure on.

    Read the article

  • C - Discard the edges of an arbitrary level of a multidimensional array

    - by Medivh
    I have some geographical data, that I'm trying to parse into a usable format. The data is kept in NetCDF files, and is read out as a multidimensional array. My problem comes because the source of the geographical data has a strip of longitude on each side of the grid that overlaps the other side. That is, I have a longitude point of -1 degree, and another of 361 degrees. Unfortunately, I've got time, latitude, and sometimes height as dimensions in this array as well, and I have no way of predicting in advance where each dimension will be in the list (or if it's a three dimensional array, or a four dimensional array). Further complicating the problem, the array can be of floats, doubles or integers, so I have to pass it around as a void. Are there any NetCDF tools that I can use to pre-prepare the files? If not, how would you suggest I go about stripping the excess longitudes?

    Read the article

  • Fastest way to read/store lots of multidimensional data? (Java)

    - by RemiX
    I have three questions about three nested loops: for (int x=0; x<400; x++) { for (int y=0; y<300; y++) { for (int z=0; z<400; z++) { // compute and store value } } } And I need to store all computed values. My standard approach would be to use a 3D-array: values[x][y][z] = 1; // test value but this turns out to be slow: it takes 192 ms to complete this loop, where a single int-assignment int value = 1; // test value takes only 66 ms. 1) Why is an array so relatively slow? 2) And why does it get even slower when I put this in the inner loop: values[z][y][x] = 1; // (notice x and z switched) This takes more than 4 seconds! 3) Most importantly: Can I use a data structure that is as quick as the assignment of a single integer, but can store as much data as the 3D-array?

    Read the article

  • How to check if *number* is in a array

    - by Emil
    Pretty basic programming question, I know PHP have a function for it, but does the iPhone OS have one? I want to check if the current indexPath is a value in an array. PHP Example: <?php $indexPath = 3; $array = array("0", "1", "2", "3", "4"); if (in_array($indexPath, $array)) { // Do something } ?> Does anybody know how to do the same thing inthe iPhone OS?

    Read the article

  • return a php associative array to javascript array

    - by Eric Sim
    I am trying to return a php associative array to javascript array through ajaxRequest.responseText Here's what I do. First in php, I do this: $encoded = json_encode($thisarray); echo $encoded; If I echo $encoded, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"} Then in js script, thisarray = new Array(); thisarray = ajaxRequest.responseText; If I alert thisarray, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"} That's wrong since alerting an array should give error. But in this case, when I alert thisarray, I get the full array!! Needless to say, I can't call my value out of thisarray, since it is yet defined as an array. Anyone can tell me what am I missing here?

    Read the article

  • transforming flat php array into multidimensional one based on key value?

    - by PopRocks4344
    I have a flat array that I'm trying to make multidimensional. Basically, I want to find the items that have parents and create a subarray for that parent id. Right now (and this is simplified), it looks like this: Array ( [0] => stdClass Object ( [id] => 1 [parent] => 0 [name ] => Parent1 ) [1] => stdClass Object ( [id] => 7 [parent] => 1 [name] => Child1 ) [2] => stdClass Object ( [id] => 9 [parent] => 1 [name] => Child2 ) [3] => stdClass Object ( [id] => 2 [parent] => 0 [name ] => Parent2 ) [4] => stdClass Object ( [id] => 88 [parent] => 2 [name] => Childof2 ) ) I'm trying to make this: Array ( [0] => stdClass Object ( [id] => 1 [parent] => 0 [name ] => Parent1 [children] => stdClass Object ( [1] => stdClass Object ( [id] => 7 [parent] => 1 [name] => Child1 ) [2] => stdClass Object ( [id] => 9 [parent] => 1 [name] => Child2 ) ) ) [1] => stdClass Object ( [id] => 2 [parent] => 0 [name ] => Parent2 [children] => stdClass Object ( [0] => stdClass Object ( [id] => 88 [parent] => 2 [name] => Childof2 ) ) ) )

    Read the article

  • Array sum of difference of first smallest k elment

    - by prateeak ojha
    Hi i come across this challenge on an online programing challange the task is so simple for ex WE have to variable N and K where N is where N is lenght of array and we have to find sum of duiffrence of K smallest element of array as Sample Input 10 4 1 2 3 4 10 20 30 40 100 200 Sample Output 10 Explanation #0 We have 10 as N size of array and K is 4 here the next N values are array's elments in order to find sum of diffrences we will takek smallest values from array which are 1,2,3,4 then will perform operation(sum of difference) as |1-2| + |1-3| + |1-4| + |2-3| + |2-4| + |3-4| = 10 I tried solving the problem and found a way through which i can solve the problem wit N^3 complexity but my solution is rejected i need a approach to solve the problem with n complexity i still can't figure out a way .. looked at some solution but coud'nt find the exact way to approach. if anybody have a better idea and would like to share it would be appreciable thanks in advance

    Read the article

  • Sorting an array in ascending order without losing the index Objective-C

    - by thary
    Hello all, I have an array for instance, Array { 3.0 at Index 0 2.0 at Index 1 3.5 at Index 2 1.0 at Index 4 } I would like to get sort it in ascending order without losing the index in the first place, like this, Array { 1.0 at Index 4 2.0 at Index 1 3.0 at Index 0 3.5 at Index 2 } When I sort the array using this, NSArray *sortedArray = [hArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; [knnRecog sortUsingDescriptors:[NSArray arrayWithObject:sortAsc]]; I lose the index. Does anyone know a way to preserve the index after sorting the array? Thanks

    Read the article

  • array_merge vs array_value for resetting array index

    - by Jamex
    I have 1 array that I want to re-index. I have found that both array_values and array_merge functions can do the job (and I don't need 2 arrays for the array_merge function to work). Which is faster for a very large array? I would benchmark this, but I don't know how and don't have the large array yet. Before re-index: Array ( [0] => AB [4] => EA [6] => FA [9] => DA [10] => AF ) After re-index: Array ( [0] => AB [1] => EA [2] => FA [3] => DA [4] => AF )

    Read the article

  • How to structurally display a multi-dimensional array in PHP?

    - by Jaime Cross
    How can I display the contents of an array as follows: Company Name - Username1 - Username2 Another Company Name - Username3 The array I have created is as follows: $array[1]['company_id'] = '12'; $array[1]['company_name'] = 'ABC Company'; $array[1]['company_type'] = 'default'; $array[1]['user_id'] = '23'; $array[1]['user_name'] = 'Andrew'; $array[2]['company_id'] = '12'; $array[2]['company_name'] = 'ABC Company'; $array[2]['company_type'] = 'default'; $array[2]['user_id'] = '27'; $array[2]['user_name'] = 'Jeffrey'; $array[3]['company_id'] = '1'; $array[3]['company_name'] = 'Some Company'; $array[3]['company_type'] = 'default'; $array[3]['user_id'] = '29'; $array[3]['user_name'] = 'William'; $array[4]['company_id'] = '51'; $array[4]['company_name'] = 'My Company'; $array[4]['company_type'] = 'default'; $array[4]['user_id'] = '20'; $array[4]['user_name'] = 'Jaime';

    Read the article

  • Converting 3 dimension byte array to a single byte array [on hold]

    - by Andrew Simpson
    I have a 3 dimensional byte array. The 3-d array represents a jpeg image. Each channel/array represents part of the RGB spectrum. I am not interested in retaining black pixels. A black pixel is represented by this atypical arrangement: myarray[0,0,0] =0; myarray[0,0,1] =0; myarray[0,0,2] =0; So, I have flattened this 3d array out to a 1d array by doing this byte[] AFlatArray = new byte[width x height x 3] and then assigning values respective to the coordinate. But like I said I do not want black pixels. So this array has to only contain color pixels with the x,y coordinate. The result I want is to re-represent the image from the i dimension byte array that only contains non-black pixels. How do I do that? It looks like I have to store black pixels as well because of the xy coordinate system. I have tried writing to a binary file but the size of that file is greater than the jpeg file as the jpeg file is compressed. I am using c#.

    Read the article

  • VBA-Excel return multidimensional array from a function

    - by alesdario
    I'm trying to write a function which returns a multidimensional array. The problem is that the size of the array isn't defined. My array is initialized in the function below my_list() Dim my_list() As String Public Sub Load_My_List() Dim last_column As Integer last_column = some_helper.Get_Last_Column(somw_worksheet) 'my array is resized in this point ReDim my_list(1 To last_column - 1, 1) Dim i As Integer i = 1 For index= 2 To ultima_colonna my_list(i, 0) = some_worksheet.Cells(2, index).value my_list(i, 1) = index i = i + 1 Next index End Sub So, how can i write a function which returns my_list ? Something like the function below generate a mismacthing type error Public function Get_My_List as String() Get_My_List = my_list End Function and how can i call this function properly? I think that something like Dim test() as String test = Get_My_List will doesn't work

    Read the article

  • Understanding c-pointers for rows in 2-dimensional array

    - by utdiscant
    I have the following code: int main() { int n = 3, m = 4, a[n][m], i, j, (* p)[m] = a; for (i = 0; i < n; i++) for (j = 0; j < m; j++) a[i][j] = 1; p++; (*p)[2] = 9; return 0; } I have a hard time understanding what p is here, and the consequences of the operations on p in the end. Can someone give me a brief explanation of what happens. I know c-pointers in their simple settings, but here it get slightly more complicated.

    Read the article

  • Matching array elements to get an array element at another index

    - by bccarlso
    I have a PHP array that I'm using to generate an HTML form. The PHP array is this: <?php $vdb = array ( array( "Alabama", 275), array( "Alaska", 197), array( "Arizona", 3322)); ?> The PHP to generate the HTML form is below. I need to have the value be the name of the state, because there is some AJAX I'm using to display which states a user has chosen. <?php echo "<table border='1'><thead><tr><th></th><th>State</th><th>Contacts</th><th>Email</th></tr></thead>"; for ($row = 0; $row < 42; $row++) { echo "<tr><td class='input_button'><input type='checkbox' name='vdb[]' value='".$vdb[$row][0]."' title='".$vdb[$row][1]."' /></td>"; echo "<td>".$vdb[$row][0]."</td>"; echo "<td>".$vdb[$row][1]."</td>"; } echo "</table>"; ?> What I'm trying to do is, on submission of the form, with the states the user selected, loop through the PHP array and total the numbers from the selected states. So if I checked Alabama and Alaska, I'd want to add 275 + 197. This is what I thought would have worked, but it's not: <?php $vendors = array(); if (isset($_POST["vdb"])) { $vendors = $_POST["vdb"]; } $ven_i = 0; $ven_j = 0; $ven_total = 0; foreach ($vendors as $value) { foreach ($vdb as $vdb_value) { if ($vendors[$ven_i] == $vdb[$ven_j][0]) { $ven_total += $vdb[$ven_j][1]; } $ven_j++; } $ven_i++; } ?> and then $ven_total should be the total I'm looking for. However, $ven_total just ends up being the first checkbox selected, and it ignores the rest. I am doing this correctly with the AJAX, displaying the total on the front end, but I don't know how to pass that on to the form submission. I'd rather not using GET and URL variables, because a user could type something into the URL and modify the count. Any idea what I'm doing wrong, or a better way to approach this that I would be able to understand? (Very much a novice programmer.)

    Read the article

  • Formula needed: Sort array to array-"snaked"

    - by aw
    After the you guys helped me out so gracefully last time, here is another tricky array sorter for you. I have the following array: a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] I use it for some visual stuff and render it like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Now I want to sort the array to have a "snake" later: // rearrange the array according to this schema 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 // the original array should look like this a = [1,2,3,4,12,13,14,5,11,16,15,6,10,9,8,7] Now I'm looking for a smart formula / smart loop to do that ticker = 0; rows = 4; // can be n cols = 4; // can be n originalArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; newArray = []; while(ticker < originalArray.length) { //do the magic here ticker++; } Thanks again for the help.

    Read the article

  • Submitting a multidimensional array via POST with php

    - by Fireflight
    I have a php form that has a known number of columns (ex. top diameter, bottom diameter, fabric, colour, quantity), but has an unknown number of rows, as users can add rows as they need. I've discovered how to take each of the fields(columns) and place them into an array of their own. <input name="topdiameter['+current+']" type="text" id="topdiameter'+current+'" size="5" /> <input name="bottomdiameter['+current+']" type="text" id="bottomdiameter'+current+'" size="5" /> So what I end up with in the HTML is: <tr> <td><input name="topdiameter[0]" type="text" id="topdiameter0" size="5" /></td> <td><input name="bottomdiameter[0]" type="text" id="bottomdiameter0" size="5" /></td> </tr> <tr> <td><input name="topdiameter[1]" type="text" id="topdiameter0" size="5" /></td> <td><input name="bottomdiameter[1]" type="text" id="bottomdiameter0" size="5" /></td> </tr> ...and so on. What I would like to do now is take all the rows and columns put them into a multidimensional array and email the contents of that to the client (preferably in a nicely formatted table). I haven't been able to really comprehend how to combine all those inputs and selects into a nice array. At this point, I'm going to have to try to use several 1D arrays, although I have the idea that using a single 2D array would be a better practice than using several 1D arrays.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >