Search Results

Search found 16413 results on 657 pages for 'array manipulation'.

Page 8/657 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • how to sort a multidemensional array by an inner key

    - by Derek Vance
    i have this enormous array that i am pulling from an API for BattleField Bad Company 2, and the soldier stats can be pulled as a multi dimensional array with an inner array for each soldier, however the API sormats it sorting the soldiers by name alphabetically, i want to sort them by rank (which is just another key within that soldiers array). ive been trying to figure this out for days, anyone have any ideas? (ie sort the array by $arr[players][][rank] here is a bit of the array Array ( [players] = Array ( [0] = Array ( [name] = bigjay517 [rank] = 29 [rank_name] = SECOND LIEUTENANT II [veteran] = 0 [score] = 979440 [level] = 169 [kills] = 4134 [deaths] = 3813 [time] = 292457.42 [elo] = 319.297 [form] = 1 [date_lastupdate] = 2010-03-30T14:06:20+02:00 [count_updates] = 13 [general] = Array ( [accuracy] = 0.332 [dogr] = 86 [dogt] = 166 [elo0] = 309.104 [elo1] = 230.849 [games] = 384 [goldedition] = 0 [losses] = 161 [sc_assault] = 146333 [sc_award] = 567190 [sc_bonus] = 35305 [sc_demo] = 96961 [sc_general] = 264700 [sc_objective] = 54740 [sc_recon] = 54202 [sc_squad] = 53210 [sc_support] = 70194 [sc_team] = 21215 [sc_vehicle] = 44560 [slevel] = 0 [spm] = 0 [spm0] = 0 [spm1] = 0 [srank] = 0 [sveteran] = 0 [teamkills] = 67 [udogt] = 0 [wins] = 223 )

    Read the article

  • foreach loop corrupting my array?

    - by WmasterJ
    Explanation I have a multidimensional array that is iterated over to created a categorized view of people with different research interests. The main array look something like this: Array ( ... ['Cell Biology'] => Array(4 elements) ['Molecular'] => Array(6 elements) ['Biology Education'] => Array(14 elements) ['Plant Biology'] => Array(19 elements) <--- Last element in array ) I know that the entire array is intact and correctly structured. The only information that is inside these array is an user id, like so: Array ('Plant Biology') 19 elements ( [0] => 737 [1] => 742 [2] => 748 ... ) My problem is that after i run the main array through a foreach loop the last 'sub-array' gets messed up. By messed up I mean that what you see about instead look like: String (13 characters) 'Plant Biology' This is without doing at all anything inside the loop with to the array that gets corrupted. Any tips to what it might be? PHP Code // ---> Array is OK here echo "<h2>Research divided</h2>"; // Loop areas and list them in 2 columns foreach($research['areas'] as $area => $areaArray) { // ---> Here it is already corrupted $count = count($areaArray); if($count > 0) { echo "<h3>$area</h3><hr/>"; echo "<table class='area_list'><tr>"; // Loop users within areas, divided up in 2 columns for($i=0 ; $i<$count ; $i++) { $uid = $areaArray[$i]; echo "<li>$uid</li>"; } echo "</tr></table>"; } }

    Read the article

  • c# Multi diemention (array, arraylist, or hashtable) ?

    - by Data-Base
    hello, I'm trying to figure out how to build a multi dimensional "array" that is: flexible size use 2 keys 1st key is int (flexible) 2nd key is string (kind of limited) the use will be like console.writelen(array[0]["firstname"]); console.writelen(array[0]["lastname"]); console.writelen(array[0]["phone"]); console.writelen(array[1]["firstname"]); console.writelen(array[1]["lastname"]); console.writelen(array[1]["phone"]); ..... ..... console.writelen(array[x]["firstname"]); console.writelen(array[x]["lastname"]); console.writelen(array[x]["phone"]); something like this

    Read the article

  • PHP : flatten array - fastest way?

    - by Industrial
    Is there any fast way to flatten an array and select subkeys ('key'&'value' in this case) without running a foreach loop, or is the foreach always the fastest way? Array ( [0] => Array ( [key] => string [value] => a simple string [cas] => 0 ) [1] => Array ( [key] => int [value] => 99 [cas] => 0 ) [2] => Array ( [key] => array [value] => Array ( [0] => 11 [1] => 12 ) [cas] => 0 ) ) To: Array ( [int] => 99 [string] => a simple string [array] => Array ( [0] => 11 [1] => 12 ) )

    Read the article

  • Why I lose certain values from array?

    - by blankon91
    I've the code to input the values dynamically, when I use it to add the values for the first time, it's fine, but when I want to edit it, the old values didn't inserted on sql query but the new values inserted Here is the example: http://i.stack.imgur.com/dwugS.jpg here is the code: ============the function================= sub ShowItemfgEdit(query,selItemName,defValue,num,cdisable) response.write "<select " & cdisable & " num=""" & num & """ id=""itemCombo"" name=""" & selItemName & """ class=""label"" onchange=""varUsage.ChangeSatuanDt(this)"">" if NOT query.BOF then query.moveFirst WHILE NOT query.EOF tulis = "" if trim(defValue) = trim(query("ckdbarang")) then tulis = "selected" end if response.write "<option value=""" & trim(query("ckdbarang")) & """" & tulis & ">" & trim(query("ckdbarang")) & " - " & trim(query("vnamabarang")) query.moveNext WEND end if response.write "</select>" end sub ============calling the function================ <td class="rb" align="left"><% call ShowItemfgEdit(qGetItemfgGrp,"fitem",qGetUsageDt("ckdfg"),countLine,readonlyfg) %></td> ==============post the value====================== <input type="hidden" name="fitem" value=""> ================get the value=================== for i = 1 to request.form("hdnOrderNum") if request.form("selOrdItem_" & i) <> "" then 'bla...blaa...blaa... ckdfg = trim(request.form("fitem_" & i)) '<==here is the problem objCommand.commandText = "INSERT INTO IcTrPakaiDt " &_ "(id, id_h, ckdunitkey, cnopakai, dtglpakai, ckdbarang, ckdgudang, nqty1, nqty2, csatuan1, csatuan2, nqtypakai, csatuanpakai, vketerangan, cJnsPakai, ckdprodkey, ckdfg, ncountstart, ncountstop, ncounttotal) " &_ " VALUES " &_ " (" & idDt & ",'" & idHd & "','" & selLoc & "','" & nopakai & "','" & cDate(request.form("hdnUsageDate")) & "','" & trim(ckdbarang) & "','" & trim(ckdgudang) & "'," & nqty1 & "," & nqty2 & ",'" & trim(csatuan1) & "','" & trim(csatuan2) & "'," & nqtypakai & ",'" & csatuanpakai & "','" & trim(keteranganItem) & "','" & trim(cjnspakai) & "','" & ckdprodkey & "','" &ckdfg& "'," & cnt1 & "," & cnt2 & "," & totalcnt & ")" set qInsertPakaiDt = objCommand.Execute end if next problem: old value of ckdfg didn't inserted to query, but the new value inserted. How to fix this bug?

    Read the article

  • Combining array values in multilevel array

    - by James Huckabone
    I have an array like so: array( 'a'=>array( 'a'=>3, 'f'=>5, 'sdf'=>0), 't'=>array( 'a'=>1, 'f'=>2, 'sdf'=>5), 'pps'=>array( 'a'=>1, 'f'=>2, 'sdf'=>3) ); Notice how the sub-arrays are the same for each top-level array. If I wanted to, what's the easiest way to combine the sub-arrays so that I'm left with a one-dimensional array like: array( 'a'=>5, 'f'=>9, 'sdf'=>8 );

    Read the article

  • Slow parity initialization of RAID-5 array on HP Smart Array 411 controller

    - by Rob Nicholson
    On 29th October 2011, I built a RAID-5 array using 4 x 146.8GB Seagate SAS ST3146855SS drives running at 15k connected to a PowerEdge R515 with HP Smart Array P411 controller running Windows 2008 (so nothing particularly unusual). I know that parity initialisation of a RAID-5 array can take some time but it's still running after 2.5 weeks which seems a little unusual. I'd previously built another array on the same controller using 4 x 2TB SATA-2 drives and that did take a while to complete but a) I'm sure it was less than 2.5 weeks, b) that array was ~12 times bigger and c) during initialization, the percentrage slowly increased each day. At the moment, the status display for this new 2nd array simply says "Parity Initialization Status: In Progress" and it's said that since the start. It's this lack of change on the status that worries me the most - feels like it's not actually doing anything. Do you think something has gone wrong or am I being unpatient and for some reason, the status not increasing is normal? I kind of expected a much smaller array on faster drives (15k SAS versus 7.5k SATA-2) to build in a few days. This is our primary SAN running StarWind so my "have a play" options are very limited. This 2nd array is currently in use for one small virtual disk so I could shut the target machine down, move the virtual disk to another drive and try rebuilding.

    Read the article

  • PHP Function needed for GENERIC sorting of a recordset array

    - by donbriggs
    Somebody must have come up with a solution for this by now. 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. 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

  • Adding an Array inside an array in a PHP function

    - by bateman_ap
    I have created a function in PHP that calls a webservice and parses through the result, assinging values to variables and returning them all as an Array. This all works perfectly, however I have come across a need to have an "array within my array" I am assigning values as below: $productName = $product->Name; $productID = $product->ID; $productArray = array( 'productName' => "$productName", 'productID' => "$productID" ); return $productArray; However I now have a piece of data that comes back with multiple results so I need to have a additional array to store these, I am getting the values from the returned XML using a foreach loop, however I want to be able to add them to the array with a name so I can reference them in the returned data, this is where I have a problem... $bestForLists = $product->BestFors; foreach( $bestForLists as $bestForList ) { $productBestFors = $bestForList->BestFor; foreach( $productBestFors as $productBestFor ) { $productBestForName = $productBestFor->Name; $productBestForID = $productBestFor->ID; } } I tried creating an array for these using the below code: $bestForArray[] = (array( "productBestForID" => "$productBestForID", "productBestForName" => "$productBestForName" )); And then at the end merging these together: $productArray= array_merge($productArray,$bestForArray); If I print out the returned value I get: Array ( [productName] => Test Product [productID] => 14128 [0] => Array ( [productBestForID] => 56647 [productBestForName] => Lighting ) [1] => Array ( [productBestForID] => 56648 [productBestForName] => Sound ) ) I would like to give the internal Array a name so I can reference it in my code, or is there a better way of doing this, at the moment I am using the following in my PHP page to get values: $productName = $functionReturnedValues['productName']; I would like to use the following to access the array I could then loop through: $bestForArray = $functionReturnedValues['bestForArray']; Hope someone can help

    Read the article

  • How to combine these two PHP arrays ?

    - by Annan
    I have two arrays in php that are part of an image management system. weighted_images A multidimensional array. Each sub array is an associative array with keys of 'weight' (for ordering by) and 'id' (the id of the image). array( 156 => array('weight'=>1, 'id'=>156), 784 => array('weight'=>-2, 'id'=>784), ) images This array is user input. It's an array of image ids. array(784, 346, 748) I want to combine them in to a single array of ids ordered by the weight of the image. If an image doesn't have a weight append to the end. It's not a particularly hard problem however my solution is far from elegant and can't help thinking that there must be a better way to do this. $t_images = array(); foreach ($weighted_images as $wi) { if ( in_array($wi['id'], $images) ) { $t_images[$wi['weight']] = $wi['id']; } } foreach ($images as $image) { if ( !$weighted_images[$image] ) { $t_images[] = $image; } } $images = $t_images; Question: Is there a better way to do this?

    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

  • All possibilities in 2d array

    - by valli-R
    I have this array: $array = array ( array('1', '2', '3'), array('!', '@'), array('a', 'b', 'c', 'd'), ); And I want to know all character combination of sub arrays.. for example : 1!a 1!b 1!c 1!d 1@a 1@b 1@c 1@d 2!a 2!b 2!c 2!d 2@a 2@b ... Currently I am having this code : for($i = 0; $i < count($array[0]); $i++) { for($j = 0; $j < count($array[1]); $j++) { for($k = 0; $k < count($array[2]); $k++) { echo $array[0][$i].$array[1][$j].$array[2][$k].'<br/>'; } } } It works, but I think it is ugly, and when I am adding more arrays, I have to add more for. I am pretty sure there is a way to do this recursively, but I don't know how to start/how to do it. A little help could be nice! Thanks you!

    Read the article

  • Anyone Know a Great Sparse One Dimensional Array Library in Python?

    - by TheJacobTaylor
    I am working on an algorithm in Python that uses arrays heavily. The arrays are typically sparse and are read from and written to constantly. I am currently using relatively large native arrays and the performance is good but the memory usage is high (as expected). I would like to be able to have the array implementation not waste space for values that are not used and allow an index offset other than zero. As an example, if my numbers start at 1,000,000 I would like to be able to index my array starting at 1,000,000 and not be required to waste memory with a million unused values. Array reads and writes needs to be fast. Expanding into new territory can be a small delay but reads and writes should be O(1) if possible. Does anybody know of a library that can do it? Thanks!

    Read the article

  • How to add values in multidimensional array?

    - by vaiji
    I have a array like the bellow. Array ( [1] => Array ( [TotalPosts] => 46 [AgentSchemeNumber] => 11 [AgentName] => Vaiji ) [2] => Array ( [TotalPosts] => 3 [AgentSchemeNumber] => 22 [AgentName] => Vaiji ) [3] => Array ( [TotalPosts] => 0 [AgentSchemeNumber] => 33 [AgentName] => Vicky ) [4] => Array ( [TotalPosts] => 0 [AgentSchemeNumber] => 44 [AgentName] => Raja ) [5] => Array ( [TotalPosts] => 18 [AgentSchemeNumber] => 55 [AgentName] => Rama ) [6] => Array ( [TotalPosts] => 13 [AgentSchemeNumber] => 66 [AgentName] => Udaya ) ) Here AgentName vaiji contain 2 records. I want a output like Array ( [1] => Array ( [TotalPosts] => 49 [AgentSchemeNumber] => 11 or 22 (any number) [AgentName] => Vaiji ) [2] => Array ( [TotalPosts] => 0 [AgentSchemeNumber] => 33 [AgentName] => Vicky ) [3] => Array ( [TotalPosts] => 0 [AgentSchemeNumber] => 44 [AgentName] => Raja ) [4] => Array ( [TotalPosts] => 18 [AgentSchemeNumber] => 55 [AgentName] => Rama ) [5] => Array ( [TotalPosts] => 13 [AgentSchemeNumber] => 66 [AgentName] => Udaya ) ) Please help me how to do it?

    Read the article

  • "Simple" sort a nested array using array_multisort or native PHP functions instead of my own foreach loop

    - by Ana Ban
    I have the following array of days of the week, with each day having hours of the day (the whole array represents the schedule of a part-time employee): Array ( [7] => Array ( [0] => 15 [1] => 14 [2] => 13 [3] => 11 [4] => 12 [5] => 10 ) [1] => Array ( [0] => 10 [1] => 13 [2] => 12 ) [6] => Array ( [0] => 14 ) [3] => Array ( [0] => 4 [1] => 5 [2] => 6 ) ) and I simply need to: sort asc each sub-array (2nd dimension) - no need to maintain the numeric keys, values are integers sort asc the 1st dimension and maintain the numeric, integer keys ie: Array ( [1] => Array ( [0] => 10 [1] => 12 [2] => 13 ) [3] => Array ( [0] => 4 [1] => 5 [2] => 6 ) [6] => Array ( [0] => 14 ) [7] => Array ( [0] => 10 [1] => 11 [2] => 12 [3] => 13 [4] => 14 [5] => 15 ) ) Additional info: only the keys of the 1st dimension and the values of the 2nd dimension (and of course their association) are meaningful to my use-case the 1st dimension can have at most 7 values, ranging from 1-7 (days of the week), and will have at least 1 value (1 day) the 2nd dimension can have at most 24 values, ranging from 0-23 (hours of each day), and will have at least 1 value (1 hour per day) I know I can do this with a foreach on the whole ksorted array and sort each 2nd dimension array: ksort($sched); foreach ($sched as &$array) sort($array); unset($array); but I was hoping I could achieve this with native php array function(s) instead. My search led me to try array_multisort(array_values($array), array_keys($array), $array) but I just can't make it work.

    Read the article

  • Remove values from array on foreach PHP

    - by user104531
    I have an array like this: Array ( [0] => Array ( [id] => 68 [type] => onetype [type_id] => 131 [name] => name1 ) [1] => Array ( [id] => 32 [type] => anothertype [type_id] => 101 [name] => name2 ) ) I need to remove some arrays from it if the users has permissions or not to see that kind of type. I am thinking on doing it with a for each, and do the needed ifs inside it to remove or let it as it. My question is: What's the most efficent way to do this? The array will have no more than 100 records. But several users will request it and do the filtering over and over.

    Read the article

  • Ruby - Subclassing array to make it randomize when flattened

    - by Markus O'Reilly
    I'm trying to subclass Array in ruby to make it randomize its elements when flatten! is called. Looking at the source code for Array#flatten (http://ruby-doc.org/core/classes/Array.src/M002218.html), it looks like it should recursively call flatten! on any array contained within an array. So, I tried doing something like this: class RandArray < Array def randomize! self.sort!{rand(3)-1} end def flatten! randomize! super end end However, when a normal array contains my RandArray and flatten is called on the normal array, flatten! is never called in my array. I figure ruby is just calling some other method to flatten the arrays recursively, but I can't figure out what that is. Any tips?

    Read the article

  • generic function for extracting values from an array with one particular key in PHP

    - by Sabya
    Is it possible in PHP to extract values from an array with a particular key path and return an array of those values? I'll explain with an example: $user = array ( array( id => 1, email =>'[email protected]', project => array ('project_id' => 222, 'project_name' => 'design') ), array( id => 2, email =>'[email protected]', project => array ('project_id' => 333, 'project_name' => 'design') ) ); /** I have to write a function something like: */ $projectIds = extractValuesWithKey($user, array('project', 'project_id')); print_r($projectIds); Output: Array( [0] => 222, [1] => 333 )

    Read the article

  • Fatal error: Cannot use string offset as an array

    - by learner
    Array ( [0] = Array ( [auth_id] = 1 [auth_section] = Client Data Base [auth_parent_id] = 0 [auth_admin] = 1 [sub] = Array ( [0] = Array ( [auth_id] = 2 [auth_section] = Client Contact [auth_parent_id] = 1 [auth_admin] = 1 ) ) ) [1] => Array ( [auth_id] => 6 [auth_section] => All Back Grounds [auth_parent_id] => 0 [auth_admin] => ,4 [sub] => Array ( [0] => Array ( [auth_id] => 7 [auth_section] => Edit Custom [auth_parent_id] => 6 [auth_admin] => 1 ) ) ) [2] => Array ( [auth_id] => 20 [auth_section] => Order Mail [auth_parent_id] => 0 [auth_admin] => 1 [sub] => ) } When I process the sub inner array it shows this error how can I avoid that :)

    Read the article

  • Ruby: how to know depth of multidemensional array

    - by hqt
    This is my problem I have met in my assignment. Array A has two elements: array B and array C. Array B has two elements: array D and array E At some point, array X just contains two elements: string a and string b. I don't know how to determine how deep array A is. For example: arrA = [ [ [1,2] ] ] I have tested by: A[0][0][0] == nil which returns false. Moreover, A[0][0]..[0] == nil always returns false. So, I cannot do this way to know how deep array A is.

    Read the article

  • php multidimensional array if loop

    - by user1091558
    I have a multidimensional array like this array[value][1][1] Now i would like to implement if loop like this if ($value = array[value][1][1]) { echo "It works"; } Now it works if i assign the values like [1][1],[2][1]. Is it possible to compare the whole array. I mean if the array looks like array[value][1][1],array[value][2][1],..........,array[value][n][1] It works should be echoed. I tried like this. if ($value = array[value][][]) { echo "It works"; } But its not working. Can anyone give me the correct syntax?

    Read the article

  • split a string into a key => value array in php

    - by andy-score
    +2-1+18*+7-21+3*-4-5+6x29 The above string is an example of the kind of string I'm trying to split into either a key = value array or something similar. The numbers represent the id of a class and -,+ and x represent the state of the class (minimised, expanded or hidden), the * represents a column break. I can split this into the columns easily using explode which gives and array with 3 $key = $value associations. eg. $column_layout = array( [0] => '+2-1+18' , [1] => '+7-21+3' , [2] => '-4-5+6x29' ) I then need to split this into the various classes from there, keeping the status and id together. eg. $column1 = array( '+' => 2 , '-' => 1 , '+' => 18 ) ... or $column1 = array( array( '+' , 2 ) , array( '-' , 1 ) , array( '+' , 18 ) ) ... I can't quite get my head round this and what the best way to do it is, so any help would be much appreciated.

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >