Search Results

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

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

  • PHP Flatten Array with multiple leaf nodes

    - by tafaju
    What is the best way to flatten an array with multiple leaf nodes so that each full path to leaf is a distinct return? array("Object"=>array("Properties"=>array(1, 2))); to yield Object.Properties.1 Object.Properties.2 I'm able to flatten to Object.Properties.1 but 2 does not get processed with recursive function: function flattenArray($prefix, $array) { $result = array(); foreach ($array as $key => $value) { if (is_array($value)) $result = array_merge($result, flattenArray($prefix . $key . '.', $value)); else $result[$prefix . $key] = $value; } return $result; } I presume top down will not work when anticipating multiple leaf nodes, so either need some type of bottom up processing or a way to copy array for each leaf and process (althought that seems completely inefficient)

    Read the article

  • C# Multidimensional Array Definition

    - by Blaenk
    Can someone help me convert this to C#. I've already spent more time than I would have liked trying to do it myself and it's preventing me from actually getting any work done. I guess it seems like C# has a limitation regarding how one can define arrays. I think somewhere inside I have to keep doing new int[] but I'm not sure exactly where. You don't have to convert the whole thing, just enough so I can understand how to do it. I would really appreciate it. I would like to use integers instead of characters, by the way. Thanks again // Pieces definition char mArray [7][4][5][5] = { // Square { { {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 2, 1, 0}, {0, 0, 1, 1, 0}, {0, 0, 0, 0, 0} }, { {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 2, 1, 0}, {0, 0, 1, 1, 0}, {0, 0, 0, 0, 0} }, { {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 2, 1, 0}, {0, 0, 1, 1, 0}, {0, 0, 0, 0, 0} }, { {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 2, 1, 0}, {0, 0, 1, 1, 0}, {0, 0, 0, 0, 0} } }, // and so on and so forth, for 6 more };

    Read the article

  • Elegant way to aggregate multi-dimensional array by index key

    - by Stephen J. Fuhry
    How can I recursively find the total value of all children of an array that looks something like this? [0] => Array ( [value] => ? // 8590.25 + 200.5 + 22.4 [children] => Array ( [0] => Array ( [value] => ? // 8590.25 + 200.5 [children] => Array ( [0] => Array ( [value] => 8590.25 // leaf node ) [1] => Array ( [value] => 200.05 // leaf node ) ) ) [1] => Array ( [value] => 22.4 // leaf node ) ) )

    Read the article

  • Elegant way to aggregate multi-demensional array by index key

    - by Stephen J. Fuhry
    How can I recursively find the total value of all children of an array that looks something like this? [0] => Array ( [value] => ? // 8590.25 + 200.5 + 22.4 [children] => Array ( [0] => Array ( [value] => ? // 8590.25 + 200.5 [children] => Array ( [0] => Array ( [value] => 8590.25 // leaf node ) [1] => Array ( [value] => 200.05 // leaf node ) ) ) [1] => Array ( [value] => 22.4 // leaf node ) ) )

    Read the article

  • Recursive function for multidimensional array

    - by moja
    This is my code, and I need your help to understand it. <?php $tree = array( array( 'name' => 'Item-1', 'children' => array()), array('name' => 'Item-2', 'children' => array( array('name' => 'Item-2-1', 'children' => array()), )), array('name' => 'Item-3', 'children' => array( array('name' => 'Item-3-1', 'children' => array()), array('name' => 'Item-3-2', 'children' => array( array('name' => 'Item-3-2-1', 'children' => array()), array('name' => 'Item-3-2-2', 'children' => array()), array('name' => 'Item-3-2-3', 'children' => array( array('name' => 'Item-3-2-3-1', 'children' => array()), )), )), )), ); What i need is one recursive function, which will return all names (name). For example: Item-1 Item-2 Item-2-1 Item-3 Item-3-1 Item-3-2 ........ Thanks for your help.

    Read the article

  • CTP for Power View and SSAS Multidimensional Cubes

    - by Greg Low
    When Power View appeared, one of the big outcries was "but what about connecting to existing cubes!".Great to see that the SQL Server team have addressed that. A CTP that allows connecting Power View to SSAS Multidimensional cubes is now available:http://blogs.msdn.com/b/analysisservices/archive/2012/11/29/power-view-for-multidimensional-models-preview.aspxHelp the team get this out the door by trying it and providing feedback.

    Read the article

  • passing an array structure as an array

    - by Matias
    I'm having trouble passing a structure array as a parameter of a function struct Estructure{ int a; int b; }; and a funtion Begining(Estructure &s1[]) { //modifi the estructure s1 }; and the main would be something like this int main() { Estructure m[200]; Begining(m); }; is this valid?

    Read the article

  • How do I pass a multi-dimensional array as a GET parameter in PHP?

    - by Onema
    I have the following code. $connect = new Connection (); $response = $connect->putFile($fileName, $destination); header("Location: /test.php?response=" . $response); When I invoke header with the response, the file will stop execution, but I will have no error in the console... I am thinking maybe this array needs to be encoded for the url? if that is the case how? Thank you

    Read the article

  • Reset array keys in multidimensional array

    - by nbaumann
    I've been looking around for a solution to this with no real success. I have a multidimensional array of parents and children with no limits on depth. This is generated from a database but the issue is that the item ID becomes the key using my way of arranging a flat array into a multidimensional array like so: Array( [28] => Array ( [id] => 28 [color] => #ff24e5 [name] => Personal [parent_id] => [children] => Array ( [23] => Array ( [id] => 23 [color] => #41c3a3 [name] => Shopping [parent_id] => 28 [children] => Array ( [22] => Array ( [id] => 22 [color] => #8be32b [name] => Deals [parent_id] => 23 [children] => Array ( ) ) ) ) [150] => Array ( [id] => 150 [color] => #e9a3f0 [name] => Orders [parent_id] => 28 [children] => Array ( ) ) ) ) ) What I would like, is a function that does the following: Array ( [0] => Array ( [id] => 28 [color] => #ff24e5 [name] => Personal [parent_id] => [children] => Array ( [0] => Array ( [id] => 23 [color] => #41c3a3 [name] => Shopping [parent_id] => 28 [children] => Array ( [0] => Array ( [id] => 22 [color] => #8be32b [name] => Deals [user_id] => 1 [selected] => 0 [parent_id] => 23 [children] => Array ( ) ) ) ) [1] => Array ( [id] => 150 [color] => #e9a3f0 [name] => Orders [parent_id] => 28 [children] => Array ( ) ) ) ) ) Essentially reassign keys starting from 0. I've tried numerous methods, but I'm assuming that I need to find a recursive solution and when I tried that, it destroyed my array. I was reading up on the array_walk_recursive() function, but I don't quite know what to do beyond that. Essentially, is there a way to reset numeric keys in a multidimensional array? Thanks for the help!

    Read the article

  • Reorder a multidimensional array?

    - by JasonS
    I have the following array, I need to reorder it by average rating descending. Here is a snippet. Any idea how I would go about doing this? Thanks Array ( [0] => Array ( [id] => 3 [name] => [rating] => 0 ) [1] => Array ( [id] => 2 [name] => [rating] => 2 ) )

    Read the article

  • 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

  • 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

  • Get the top nth values from a rectangular array

    - by user355925
    I am reading a txt file for strings that represent integers. The file is space delimited. I have created an array[10,2]. Everytime the strings 1~10 is found in the file I increment array[n,0] by 1. I also feed array[n,1] with numbers 1~10. i.e. txt file contents: 1/1/1 10/1/2001 1 1 10 2 2 3 1 5 10 word word 3 3 etc.. streamreader reads 1/1/1 and determines that is is not 1~10 streamreader reads 10/1/2001 and determines that it is not 1~10 streamreader reads 1 and ++array[0,0] streamreader reads 1 and ++array[0,0] streamreader reads 10 and ++array[9,0] etc.. The result will be: '1' was found 3 times '2' was found 2 times '3' was found 3 times '5' was found 1 time '10' was found 2 times My problem is that I need this array placed in order(sorted) by value of column 0 so that it would be: 1 3 2 10 5

    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

  • Selecting a multi-dimensional array in LINQ

    - by mckhendry
    I have a task where I need to translate a DataTable to a two-dimensional array. That's easy enough to do by just looping over the rows and columns (see example below). private static string[,] ToArray(DataTable table) { var array = new string[table.Rows.Count,table.Columns.Count]; for (int i = 0; i < table.Rows.Count; ++i) for (int j = 0; j < table.Columns.Count; ++j) array[i, j] = table.Rows[i][j].ToString(); return array; } What I'd really like to do is use a select statement in LINQ to generate that 2D array. Unfortunately it looks like there is no way in LINQ to select a multidimensional array. Yes, I'm aware that I can use LINQ to select a jagged array, but that's not what I want. Is my assumption correct, or is there a way to use LINQ to select a multi-dimensional array?

    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

  • 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

  • Merge the sub array if it has the save id value?

    - by sophie
    I have an array and I want to merge the sub array that have the same id value together: <?php $a = Array( Array ( "id" => 1, "id_categorie" => 1, "nb" => 18 ), Array ( "id" => 1, "id_categorie" => 8, "nb" => 14 ), Array ( "id" => 2, "id_categorie" => 10, "nb" => 15 ) ); $result = array(); foreach ($a as $k=>$v){ $result[$v['id']] =$v; } echo '<pre>'; print_r($result); echo '</pre>'; ?> I GOT: Array ( [1] => Array ( [id] => 1 [id_categorie] => 8 [nb] => 14 ) [2] => Array ( [id] => 2 [id_categorie] => 10 [nb] => 15 ) ) BUT WHAT I WANT IS : Array ( [1] => Array ( Array ( "id_categorie" => 1, "nb" => 18 ), Array ( "id_categorie" => 8, "nb" => 14 ) ) [2] => Array ( [id_categorie] => 10 [nb] => 15 ) ) Anyone could tell me how to do this? thanks

    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

  • Search and remove an element in mulit-dimentional array in php depending on a criteria

    - by Nadeem
    I've a simple question about multi-dim array, I want to remove any redundent element let's say in my case, [serviceMethod] => PL is coming 2 times, I want to search 'PL' with respect of [APIPriceTax] if an element has a lower price I want to keep it and remove the other one in array Array ( [0] => Array ( [carrierIDs] => 150 [serviceMethod] => CP [APIPriceTax] => 30.63 [APIPriceWithOutTax] 28.32 [APIServiceName] => Xpresspost USA [APIExpectedTransitDay] => 2 ) [1] => Array ( [carrierIDs] => 155 [serviceMethod] => PL [APIPriceTax] => 84.13 [APIPriceWithOutTax] => 73.8 [APIServiceName] => PurolatorExpressU.S. [APIExpectedTransitDay] => 1 ) [2] => Array ( [carrierIDs] => 164 [serviceMethod] => PL [APIPriceTax] => 25.48 [APIPriceWithOutTax] => 22.35 [APIServiceName] => PurolatorGroundU.S. [APIExpectedTransitDay] => 3 ) ) This is my pseudo code: Where $carrierAddedToList is the actual array $newCarrierAry = function($carrierAddedToList) { $newArray = array(); foreach($carrierAddedToList as $cV => $cK) { if( !in_array($cK['serviceMethod'],$newArray) ) { array_push($newArray, $cK['serviceMethod']); } } return $newArray; } ; print_r($newCarrierAry($carrierAddedToList));

    Read the article

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