Search Results

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

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

  • Dynamic Array traversal in PHP

    - by Kristoffer Bohmann
    I want to build a hierarchy from a one-dimensional array and can (almost) do so with a more or less hardcoded code. How can I make the code dynamic? Perhaps with while(isset($array[$key])) { ... }? Or, with an extra function? Like this: $out = my_extra_traverse_function($array,$key); function array_traverse($array,$key=NULL) { $out = (string) $key; $out = $array[$key] . "/" . $out; $key = $array[$key]; $out = $array[$key] ? $array[$key] . "/" . $out : ""; $key = $array[$key]; $out = $array[$key] ? $array[$key] . "/" . $out : ""; $key = $array[$key]; $out = $array[$key] ? $array[$key] . "/" . $out : ""; return $out; } $a = Array(102=>101, 103=>102, 105=>107, 109=>105, 111=>109, 104=>111); echo array_traverse($a,104); Output: 107/105/109/111/104

    Read the article

  • String Manipulation in C

    - by baris_a
    Hi guys, I am helping my nephew for his C lab homework, it is a string manipulation assignment and applying Wang's algorithm. Here is the BNF representation for the input. <sequent> ::= <lhs> # <rhs> <lhs> ::= <formulalist>| e <rhs> ::= <formulalist>| e <formulalist> ::= <formula>|<formula> , <formulalist> <formula> ::= <letter>| - <formula>| (<formula><in?xop><formula>) <in?xop> ::= & | | | > <letter> ::= A | B | ... | Z What is the best practice to handle and parse this kind of input in C? How can I parse this structure without using struct? Thanks in advance.

    Read the article

  • PHP arrays - How to 1-dimensional array into nested multidimensional array?

    - by sombe
    When retrieving a hierarchical structure from MySQL (table with one ID column and one PARENT column signifying the hierarchical relationships), I map the result into an enumerated array as follows (for this example the numbers are arbitrary): Array ( [3] => Array ( [7] => Array () ), [7] => Array ( [8] => Array () ) ) Notice 3 is the parent of 7, and 7 is the parent of 8 (this could go on and on; and any parent could have multiple children). I wanted to shrink this array into a nested multidimensional array as follows: Array ( [3] => Array ( [7] => Array ( [8] => Array () ) ) ) That is, each NEW id is automatically assigned an empty array. Regardless, any ID's children will be pushed into their parent's array. Take a look at the following illustration for further clarification: This will probably result in a complicated recursive operation, since I always have to check whether a parent with any certain ID already exists (and if so, push the value into its array). Is there a built-in php function that can assist me with this? Do you have any idea as to how to go about constructing this? For what it's worth I'm using this to built a navigation bar in wordpress (which can contain categories, subcategories, posts... essentially anything).

    Read the article

  • Casting Type array to Generic array?

    - by George R
    The short version of the question - why can't I do this? I'm restricted to .NET 3.5. T[] genericArray; // Obviously T should be float! genericArray = new T[3]{ 1.0f, 2.0f, 0.0f }; // Can't do this either, why the hell not genericArray = new float[3]{ 1.0f, 2.0f, 0.0f }; Longer version - I'm working with the Unity engine here, although that's not important. What is - I'm trying to throw conversion between its fixed Vector2 (2 floats) and Vector3 (3 floats) and my generic Vector< class. I can't cast types directly to a generic array. using UnityEngine; public struct Vector { private readonly T[] _axes; #region Constructors public Vector(int axisCount) { this._axes = new T[axisCount]; } public Vector(T x, T y) { this._axes = new T[2] { x, y }; } public Vector(T x, T y, T z) { this._axes = new T[3]{x, y, z}; } public Vector(Vector2 vector2) { // This doesn't work this._axes = new T[2] { vector2.x, vector2.y }; } public Vector(Vector3 vector3) { // Nor does this this._axes = new T[3] { vector3.x, vector3.y, vector3.z }; } #endregion #region Properties public T this[int i] { get { return _axes[i]; } set { _axes[i] = value; } } public T X { get { return _axes[0];} set { _axes[0] = value; } } public T Y { get { return _axes[1]; } set { _axes[1] = value; } } public T Z { get { return this._axes.Length (Vector2 vector2) { Vector vector = new Vector(vector2); return vector; } public static explicit operator Vector(Vector3 vector3) { Vector vector = new Vector(vector3); return vector; } #endregion }

    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

  • String manipulation in Linux kernel module

    - by user577066
    I am having a hard time in manipulating strings while writing module for linux. My problem is that I have a int Array[10] with different values in it. I need to produce a string to be able send to the buffer in my_read procedure. If my array is {0,1,112,20,4,0,0,0,0,0} then my output should be: 0:(0) 1:-(1) 2:-------------------------------------------------------------------------------------------------------(112) 3:--------------------(20) 4:----(4) 5:(0) 6:(0) 7:(0) 8:(0) 9:(0) when I try to place the above strings in char[] arrays some how weird characters end up there here is the code int my_read (char *page, char **start, off_t off, int count, int *eof, void *data) { int len; if (off > 0){ *eof =1; return 0; } /* get process tree */ int task_dep=0; /* depth of a task from INIT*/ get_task_tree(&init_task,task_dep); char tmp[1024]; char A[ProcPerDepth[0]],B[ProcPerDepth[1]],C[ProcPerDepth[2]],D[ProcPerDepth[3]],E[ProcPerDepth[4]],F[ProcPerDepth[5]],G[ProcPerDepth[6]],H[ProcPerDepth[7]],I[ProcPerDepth[8]],J[ProcPerDepth[9]]; int i=0; for (i=0;i<1024;i++){ tmp[i]='\0';} memset(A, '\0', sizeof(A));memset(B, '\0', sizeof(B));memset(C, '\0', sizeof(C)); memset(D, '\0', sizeof(D));memset(E, '\0', sizeof(E));memset(F, '\0', sizeof(F)); memset(G, '\0', sizeof(G));memset(H, '\0', sizeof(H));memset(I, '\0', sizeof(I));memset(J, '\0', sizeof(J)); printk("A:%s\nB:%s\nC:%s\nD:%s\nE:%s\nF:%s\nG:%s\nH:%s\nI:%s\nJ:%s\n",A,B,C,D,E,F,G,H,I,J); memset(A,'-',sizeof(A)); memset(B,'-',sizeof(B)); memset(C,'-',sizeof(C)); memset(D,'-',sizeof(D)); memset(E,'-',sizeof(E)); memset(F,'-',sizeof(F)); memset(G,'-',sizeof(G)); memset(H,'-',sizeof(H)); memset(I,'-',sizeof(I)); memset(J,'-',sizeof(J)); printk("A:%s\nB:%s\nC:%s\nD:%s\nE:%s\nF:%s\nG:%s\nH:%s\nI:%s\nJ:%\n",A,B,C,D,E,F,G,H,I,J); len = sprintf(page,"0:%s(%d)\n1:%s(%d)\n2:%s(%d)\n3:%s(%d)\n4:%s(%d)\n5:%s(%d)\n6:%s(%d)\n7:%s(%d)\n8:%s(%d)\n9:%s(%d)\n",A,ProcPerDepth[0],B,ProcPerDepth[1],C,ProcPerDepth[2],D,ProcPerDepth[3],E,ProcPerDepth[4],F,ProcPerDepth[5],G,ProcPerDepth[6],H,ProcPerDepth[7],I,ProcPerDepth[8],J,ProcPerDepth[9]); return len; }

    Read the article

  • How to define a static array without a contant size in a constructor of a class? (C++)

    - by Keand64
    I have a class defined as: class Obj { public: int width, height; Obj(int w, int h); } and I need it to contain a static array like so: int presc[width][height]; however, I cannot define within the class, so it it possible to create a pointer to a 2D array (and, out of curiosity, 3, 4, and 5D arrays), have that as a member of the class, and intitalize it in the constructor like: int ar[5][6]; Obj o(5, 6, &ar); If that isn't possible, is there any way to get a static array without a contant size in a class, or am I going to have to use a dynamic array? (Something I don't want to do because I don't plan on ever changing the size of the array after it's created.)

    Read the article

  • How to remove duplicates from multidimensional array in php

    - by JackTurky
    i have an array like: Array ( [prom] => Array ( [cab] => Array ( [0] => Array ( [code] => 01 [price1] => 1000 [price2] => 2000 [available] => 2 [max] => 2 [gca] => 2 ) [1] => Array ( [code] => 04 [price1] => 870 [price2] => 2500 [available] => 3 [max] => 4 [gca] => 10 ) [2] => Array ( [code] => 01 [price1] => 1000 [price2] => 2000 [available] => 2 [max] => 2 [gca] => 2 ) [3] => Array ( [code] => 05 [price1] => 346 [price2] => 1022 [available] => 10 [max] => 2 [gca] => 20 ) ) [cab1] => Array........ ) [prom1] = Array.... ) What i have to do is to remove duplicates inside every [cab*] array.. so to have something like: Array ( [prom] => Array ( [cab] => Array ( [0] => Array ( [code] => 01 [price1] => 1000 [price2] => 2000 [available] => 2 [max] => 2 [gca] => 2 ) [1] => Array ( [code] => 04 [price1] => 870 [price2] => 2500 [available] => 3 [max] => 4 [gca] => 10 ) [2] => Array ( [code] => 05 [price1] => 346 [price2] => 1022 [available] => 10 [max] => 2 [gca] => 20 ) ) [cab1] => Array........ ) [prom1] = Array.... ) In know that there is array_unique combined with array_map to remove duplicates.. but i know that it works only on 2D array.. what can i do? can someone help me pls? thanks!!!

    Read the article

  • Array manipulation in gsettings' set command

    - by Daniel
    Is there an easy way to do array manipulation in gsettings? I am comparing gsettings to OS X's defaults command that offers the defaults domain --array key overwrite-value and defaults domain --array-add key added-value interface for manipulating arrays. As far as I can tell there is only gsettings set domain key "['overwrite-value']" available to gsettings. Not really pretty for when you want to add or remove one entry from an array. I have seen a suggestion that allow me to add to an array, but I would rather use a interface if there is one.

    Read the article

  • Sum Values in Multidimensional Array

    - by lemonpole
    Hello all. I'm experimenting with arrays in PHP and I am setting up a fake environment where a "team's" record is held in arrays. $t1 = array ( "basicInfo" => array ( "The Sineps", "December 25, 2010", "lemonpole" ), "overallRecord" => array ( 0, 0, 0, 0 ), "overallSeasons" => array ( "season1.cs" => array (0, 0, 0), "season2.cs" => array (0, 0, 0) ), "matches" => array ( "season1.cs" => array ( "week1" => array ("12", "3", "1"), "week2" => array ("8", "8" ,"0"), "week3" => array ("8", "8" ,"0") ), "season2.cs" => array ( "week1" => array ("9", "2", "5"), "week2" => array ("12", "2" ,"2") ) ) ); What I am trying to achieve is to add all the wins, loss, and draws, from each season's week to their respective week. So for example, the sum of all the weeks in $t1["matches"]["season1.cs"] will be added to $t1["overallSeasons"]["season1.cs"]. The result would leave: "overallSeasons" => array ( "season1.cs" => array (28, 19, 1), "season2.cs" => array (21, 4, 7) ), I tried to work this out on my own for the past hour and all I have gotten is a little more knowledge of for-loops and foreach-loops :o... so I think I now have the basics down such as using foreach loops and so on; however, I am still fairly new to this so bear with me! I can get the loop to point to $t1["matches"] key and go through each season but I can't seem to figure out how to add all of the wins, loss, and draw, for each individual week. For now, I'm only looking for answers concerning the overall seasons sum since I can work from there once I figure out how to achieve this. Any help will be much appreciated but please, try and keep it simple for me... or comment the code accordingly please! Thanks!

    Read the article

  • Specific complex array sorting

    - by TheDeadMedic
    Okay, a before; Array ( 'home' => array('order' => 1), 'about' => array(), 'folio' => array('order' => 2), 'folio/web' => array('order' => 2), 'folio/print' => array('order' => 1) 'contact' => array('order' => 2) ) And a desired after; Array ( 'home' => array('order' => 1), 'contact' => array('order' => 2), 'folio' => array('order' => 2), 'folio/print' => array('order' => 1), 'folio/web' => array('order' => 2), 'about' => array() ) I know, horrific (don't ask!) See how the slash in the key indicates children, and how the order is nested accordingly? And items without orders are simply shifted to the bottom. But also how multiple 'same level' items with the same order are merely sorted by key?

    Read the article

  • PHP: Recursive array function

    - by Industrial
    Hi everybody, I want to create a function that returns the full path from a set node, back to the root value. I tried to make a recursive function, but ran out of luck totally. What would be an appropriate way to do this? I assume that a recursive function is the only way? Here's the array: Array ( [0] => Array ( [id] => 1 [name] => Root category [_parent] => ) [1] => Array ( [id] => 2 [name] => Category 2 [_parent] => 1 ) [2] => Array ( [id] => 3 [name] => Category 3 [_parent] => 1 ) [3] => Array ( [id] => 4 [name] => Category 4 [_parent] => 3 ) ) The result I want my function to output when getting full path of node id#4: Array ( [0] => Array ( [id] => 1 [name] => Root category [_parent] => ) [1] => Array ( [id] => 3 [name] => Category 3 [_parent] => 1 ) [2] => Array ( [id] => 4 [name] => Category 4 [_parent] => 3 ) ) The notoriously bad example of my recursive skills: function recursive ($id, $array) { $innerarray = array(); foreach ($array as $k => $v) { if ($v['id'] === $id) { if ($v['_parent'] !== '') { $innerarray[] = $v; recursive($v['id'], $array); } } } return $innerarray; } Thanks!

    Read the article

  • String Manipulation: Spliting Delimitted Data

    - by Milli Szabo
    I need to split some info from a asterisk delimitted data. Data Format: NAME*ADRESS LINE1*ADDRESS LINE2 Rules: 1. Name should be always present 2. Address Line 1 and 2 might not be 3. There should be always three asterisks. Samples: MR JONES A ORTEGA*ADDRESS 1*ADDRESS2* Name: MR JONES A ORTEGA Address Line1: ADDRESS 1 Address Line2: ADDRESS 2 A PAUL*ADDR1** Name: A PAUL Address Line1: ADDR1 Address Line2: Not Given My algo is: 1. Iterate through the characters in the line 2. Store all chars in a temp variables until first * is found. Reject the data if no char is found before first occurence of asterisk. If some chars found, use it as the name. 3. Same as step 2 for finding address line 1 and 2 except that this won't reject the data if no char is found My algo looks ugly. The code looks uglier. Spliting using //* doesn't work either since name can be replaced with address line 1 If the data is *Address 1*Address2, split will create two indexes in the array where index 0 will have the value of Address 1 and index 2 will have the value of Address2. Where's the name. Was there a name? Any suggestion?

    Read the article

  • Convert PostgreSQL array to PHP array

    - by EarthMind
    I have trouble reading Postgresql arrays in PHP. I have tried explode(), but this breaks arrays containing commas in strings, and str_getcsv() but it's also no good as PostgreSQL doesn't quote the Japanese strings. Not working: explode(',', trim($pgArray, '{}')); str_getcsv( trim($pgArray, '{}') );

    Read the article

  • Convert between python array and .NET Array

    - by dungema
    I have a python method that returns a Python byte array.array('c'). Now, I want to copy this array using System.Runtime.InteropServices.Marshal.Copy. This method however expects a .NET array. import array from System.Runtime.InteropServices import Marshal bytes = array.array('c') bytes.append('a') bytes.append('b') bytes.append('c') Marshal.Copy(bytes, dest, 0, 3) Is there a way to make this work without copying the data? If not, how do I convert the data in the Python array to the .NET array?

    Read the article

  • Formatting associative array declaration

    - by Drew Stephens
    When declaring an associative array, how do you handle the indentation of the elements of the array? I've seen a number of different styles (PHP syntax, since that's what I've been in lately). This is a pretty picky and trivial thing, so move along if you're interested in more serious pursuits. 1) Indent elements one more level: $array = array( 'Foo' => 'Bar', 'Baz' => 'Qux' ); 2) Indent elements two levels: $array = array( 'Foo' => 'Bar', 'Baz' => 'Qux' ); 3) Indent elements beyond the array constructor, with closing brace aligned with the start of the constructor: $array = array( 'Foo' => 'Bar', 'Baz' => 'Qux' ); 4) Indent elements beyond the array construct, with closing brace aligned with opening brace: $array = array( 'Foo' => 'Bar', 'Baz' => 'Qux' ); Personally, I like #3—the broad indentation makes it clear that we're at a break point in the code (constructing the array), and having the closing brace floating a bit to the left of all of the array's data makes it clear that this declaration is done.

    Read the article

  • Javascript array length incorrect on array of objects

    - by Serenti
    Could someone explain this (strange) behavior? Why is the length in the first example 3 and not 2, and most importantly, why is the length in the second example 0? As long as the keys are numerical, length works. When they are not, length is 0. How can I get the correct length from the second example? Thank you. a = []; a["1"] = {"string1":"string","string2":"string"}; a["2"] = {"string1":"string","string2":"string"}; alert(a.length); // returns 3 b = []; b["key1"] = {"string1":"string","string2":"string"}; b["key2"] = {"string1":"string","string2":"string"}; alert(b.length); // returns 0

    Read the article

  • Sort array by keys of another array.

    - by marbrun
    Hello There are 2 arrays, both with the same length and with the same keys: $a1 = [1=>2000,65=>1354,103=>1787]; $a2 = [1=>'hello',65=>'hi',103=>'goodevening']; asort($a1); The keys of a1 and a2 are id's from a database. a1 gets sorted by value. Once sorted, how can we use the same sorting order in a2? Thanks!

    Read the article

  • Echo a multidimensional array in PHP

    - by Jennifer
    I have a multidimensional array and I'm trying to find out how to simply "echo" the elements of the array. The depth of the array is not known, so it could be deeply nested. In the case of the array below, the right order to echo would be: This is a parent comment This is a child comment This is the 2nd child comment This is another parent comment This is the array I was talking about: Array ( [0] => Array ( [comment_id] => 1 [comment_content] => This is a parent comment [child] => Array ( [0] => Array ( [comment_id] => 3 [comment_content] => This is a child comment [child] => Array ( [0] => Array ( [comment_id] => 4 [comment_content] => This is the 2nd child comment [child] => Array ( ) ) ) ) ) ) [1] => Array ( [comment_id] => 2 [comment_content] => This is another parent comment [child] => Array ( ) ) )

    Read the article

  • get the array with html array path

    - by antpaw
    hey, i have this path name from an input element interesse[angebote][flurfuerderfahrzeuge] as a string in my php var. now i need convert it somehow (with regex or explode()) so it looks like this: $_POST['interesse']['angebote']['flurfuerderfahrzeuge'] and the use eval() to get the value. But I'm sure there must be a much easier way do this. Any ideas? Thanks!

    Read the article

  • Could anyone suggest me some image manipulation techniques to be added to my image viewer??

    - by avi
    Hello, I'm trying to develop a small image viewer just as an exercise to sharpen my programming skills. So far , all the features that I could think of adding to it are zooming in and out, inverting the colors of the image and resizing. Could anyone suggest me a few more features?? You are also welcome to suggest anything which has not been implemented yet. I would like to take it as a learning challenge. Thanks.

    Read the article

  • This for array colllision function doesn't work with anything but first object in array

    - by Zee Bashew
    For some reason, this simple simple loop is totally broken. (characterSheet is my character Class, it's just a movieClip with some extra functionality) (hitBox, is basically a square movieclip) Anyway: every time hitBox make contact with a characterSheet in a different order than they were created: Nothing happens. The program only seems to be listening to collisions that are made with o2[0]. As soon as another hitBox is created, it pushes the last one out of o2[0] and the last one becomes totally useless. What's super weird is that I can hit characterSheets in any order I like.... public function collisions(o1:Array, o2:Array) { if((o1.lenght>=0)&&(o2.length>=0)){ for (var i = 0; i < o1.length; i++) { var ob1 = o1[i]; for (var f = 0; f < o1.length; f++) { var ob2 = o2[f]; if (ob1 is characterSheet) { if (ob2.hitTestObject(ob1)) { var right:Boolean = true; if (ob1.x < hitBox(ob2).origin.x) right = false; characterSheet(ob1).specialDamage(hitBox(ob2).damageType, hitBox(ob2).damage, right); }}}}}} Also it might be somewhat helpful to see the function for creating a new hitBox public function SpawnHitBox(targeted, following, atype, xoff, yoff, ... args) { var newHitBox = new hitBox(targeted, following, atype, xoff, yoff, args); badCollisionObjects.push(newHitBox); arraydictionary[newHitBox] = badCollisionObjects; addChild(newHitBox); }

    Read the article

  • Find key of parent in array / PHP

    - by 106691756905536410593
    Perhaps someone can help me out with this one: I'm using a basic search function to find an array deep within an array. The problem is, once that array is found, I'd also like to return it's parent key. Is there a PHP function that can determine the parent key of an array? Below is an example of the Search Function... Ideally I'd like to return the array that is found, as well as it's parent key. function search($array, $key, $value){ $results = array(); if (is_array($array)){ if ($array[$key] == $value){ $results[] = $array; } foreach ($array as $subarray){ $results = array_merge($results, search($subarray, $key, $value)); } } return $results; }

    Read the article

  • PHP : How to insert an array into other child array by same index?

    - by airi
    i am new to array. Hope you can help me. i have 2 array. Let say: array 1 = [[50,60],[70,80]] array 2 = ["Fire", "Marine"] array 1 index : Array([0]=Array ([0]=50 [1]=60) [1]=Array ([0]=70 [1]=80)) array 2 index : Array ([0]= Fire [1]=Marine) How i can insert array 2 into array 1 like output below : Output that i want like below: array 3 = [["Fire",50,60],["Marine",70,80]] array 3 index = (Array([0]=Array ([0]=Fire [1]=50 [2]=60) [1]=Array ([0]=Marine [1]=70 [2]=80)) Thanks

    Read the article

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