multidimensional-array

Define 2D array with loops in php

I have an array $rows where each element is a row of 15 tab-delimited values. I want to explode $rows into a 2D array $rowData where each row is an array element and each tab-delimited value is assigned to a different array element. I've tried these two methods without success. I know the first one has a coding error but I do not know ho...

How do I efficiently locate key-value pairs in a multi-dimensional PHP array?

I have an array in PHP as a result of the following query to a Wordpress database: SELECT * FROM wp_postmeta WHERE post_id = :id I am returned a multidimensional array that looks like this: Array ( [0] => Array ( [meta_id] => 380 [post_id] => 72 [meta_key] => _edit_last [meta_value] => 1 ) ... etc. What is the best way to fi...

How to combine these two PHP arrays ?

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 ...

Multi-dimensional array parsed from .csv ->commas causing mysql database insert issues

I am using Codeigniter to parse an uploaded csv file (which is a multi-dimensional array) into a database. I have tried everything to parse the comma values correctly, but the "id" column in mysql comes up short, as it reads "text", and not "text,text,text". Help!? *For reference:* print_r($data['csvData']); Array ( [0] ...

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

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,...

For each result in MySQL query, push to array (complicated)

Okay, here's what I'm trying to do. I am running a MySQL query for the most recent posts. For each of the returned rows, I need to push the ID of the row to an array, then within that ID in the array, I need to add more data from the rows. A multi-dimensional array. Here's my code thus far. $query = "SELECT * FROM posts ORDER BY id DES...

Access Violation reading elements of an array

I've written my own code to parse an .obj model file - essentially just ASCII text. The file gets parsed and stored in the class correctly according to my tests. I can read back the values (from data members) just fine in the loading function. The problem occurs when I try to read back the values in my main rendering loop. There is an a...

Obtaining the min and max of a two-dimensional array using LINQ

How would you obtain the min and max of a two-dimensional array using LINQ? And to be clear, I mean the min/max of the all items in the array (not the min/max of a particular dimension). Or am I just going to have to loop through the old fashioned way? ...

PHP array taking up too much memory

I have a multidimensional array. The array itself is fine. My problem is that the script takes up monster amounts of memory, and since I'm running this on my MAMP install on my iBook G4, my computer freezes up. Below is the full script. $query = "SELECT * FROM posts ORDER BY id DESC LIMIT 10"; $result = mysql_query($query); $posts = ar...

(PHP) Converting an array of arrays from one format into another

Hi, I currently have an array, created from a database, an example of which looks like the following: Array( [0] => Array ( objectid => 2, name => title, value => apple ), [1] => Array ( objectid => 2, name => colour, value => red ), [2] => Array ( objectid =...

C# print 2D-array in order. Please help!

Hello, I got a 2-dimentional array containing boolean values written in C#. The cols and rows of the array are to be determined by the user upon creation of the array. I then want to print out the array and it´s containing values onto the console in order. For example like this, how is this done in C#? ROWS - COLS - VALUE 1 - A - T...

VBA pasting 3 dimensional array into sheet

I have a 3 dimensional array (5 x 5 x 3) and I need to post (5 x 5 x 1) to Sheet1, (5 x 5 x 2) to Sheet2, (5 x 5 x 3) to Sheet3. Because I am building this 3 dimensional array inside 3 nested for loops, I cannot use a for loop to access the (5 x 5) part of the loop. Is there any identifier that tells excel to index all elements of an a...

PHP: Split array of strings into multi-demensional array

I have an array of timezones: $timezones = array( 'Africa/Abidjan', 'Africa/Accra', ... 'America/Argentina/Buenos_Aires', 'America/Argentina/Catamarca', ... 'Pacific/Wallis', 'UTC', ); How can I easiest split this array so that I get one like this: $timezones = array( 'Africa' => array('Abidjan', '...

Double index in Perl, why is it so?

with @a=(6,3,5,7); @b=(@a[0..3])[2..3]; print @b; #print 57 but for @b=@a[0..3][2..3]; I get a syntax error. Could someone explain why? ...

Dynamically populating 3D array in JavaScript

I am trying to populate a dynamic 3 dimensional array so I don't have to type it all out var o = { matrix: (function(n) { for (var x = 0; x < n; x ++) { for (var y = 0; y < n; y++) { for (var z = 0; z < n; z++) { this[x][y][z] = -1; } } } }).call(Array, 5), ... } The message I get is...

Fast sum of values in a multidimensional array (C#)

With a 1D array, I can use the sum method to get the sum of all the values. int[] array = {6,3,1}; Console.WriteLine(array.Sum()); With a multidimensional array (3D in my case), this can't be done. Obviously I could go all foreach on it, but this seems verbose and I suspect it will perform badly. Is there a way to flatten the array? ...

vb.net remove a row in two-dimensional array

In vb.net how do you delete a row in a two dimensional array? ...

PHP: rename multidimensional array's keys

Hello. I have a multidimensional array with strings as keys. I want to perform a function (to manipulate the strings) on those keys and then write to a new array (i.e. leave the original array unchanged). Example: $oldArr = array( "foo_old" => array("moo_old" => 1234, "woo_old" => 5678); "bar_old" => array("car_old" => 4321...

Is it possible to dynamically build a multi-dimensional array in Java?

Suppose we have the Java code: Object arr = Array.newInstance(Array.class, 5); Would that run? As a further note, what if we were to try something like this: Object arr1 = Array.newInstance(Array.class, 2); Object arr2 = Array.newInstance(String.class, 4); Object arr3 = Array.newInstance(String.class, 4); Array.set(arr1, 0, arr2); Ar...

adding an element to multidimensional array when within foreach loop (PHP)

Hi I'm trying to check if a certain category is allready selected by looping through an array of categories also I want to add another element to the array whci is just a bit to indicate is the category selcated my categories array looks like this 0=>array(category_id=>12,category_name=>"blogger") 1=>array(category_id=>13,category_na...