arrays

How to index an array?

Hello! I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it as JSON 'array', and when I decode it, I want to reach every item by its number, so I want an indexed array. How could I solve this in PHP? Tim ...

Counting blanks when merging assoctiative arrays

I'm trying to merge these 2 arrays $arr1 = array('a' => "1", 'b' => "2", 'c' => "3"); $arr2 = array('a' => "9", 'b' => "8", 'd' => "7"); into an array that looks like this $arr1 = array( 'a' => array("1", "9"), 'b' => array("2", "8"), 'c' => array("3", ""), 'd' => array("", "7") ); The tricky part is the blanks. I...

Separate multi dimensional array

Hello! I have a multi dimensional array in PHP. $f = array('one' => array(*doesntmatter*), two => array()); When I want to use it, I only want one of the arrays. (one or two or three etc) So I want to slice it into (in this case) two seperate arrays, like this: $one = array(**); $two = array(**); Can I solve this with a default fu...

javascript: best way to delete element from array without rearrange it

Hi all, i have to delete some elements of my array, but without rearrange array. If i use "delete" to delete my elements, the "holes" take up memory? var array=["A","B","C"]; delete array[1]; // array -> ["A", undefined, "C"] I think the deleted element is really deleted so it isn't take up memory space, isn't true? Thanks. ...

How do I use member functions of constant arrays in C++?

Here is a simplified version of what I have (not working): prog.h: ... const string c_strExample1 = "ex1"; const string c_strExample2 = "ex2"; const string c_astrExamples[] = {c_strExample1, c_strExample2}; ... prog.cpp: ... int main() { int nLength = c_astrExamples.length(); for (int i = 0; i < nLength; i++) cout << c_...

Does the Perl diamond operator iterate over non-magic arrays (not @ARGV)?

I don't think the following should work, but it does: $ perl -e '@a = qw/1222 2 3/; while (<@a>) { print $_ ."\n";}' 1222 2 3 $ As far as I know, Perl's <> operator shoud work on filehandle, globs and so on, with the exception of the literal <> (instead of <FILEHANDLE>), which magically iterates over @ARGV. Does anyone know if it's s...

Turning a Hash of Arrays into an Array of Hashes in Ruby

We have the following datastructures: {:a => ["val1", "val2"], :b => ["valb1", "valb2"], ...} And I want to turn that into [{:a => "val1", :b => "valb1"}, {:a => "val2", :b => "valb2"}, ...] And then back into the first form. Anybody with a nice looking implementation? ...

Is array name a pointer in C?

Is an array's name a pointer in C? If not, what is the difference between an array's name and a pointer variable? ...

Joining each item of an array with the items of another array

Consider this: [ ["a", "b"], ["c", "d"], ["e"] ] How can this be tranformed to: [ "a c e", "a d e", "b c e", "b d e" ] ...

Storing char array in a class and then returning it

Hi, I need to store a char array inside a class and then return it. I have to admit that I'm a bit confused about pointers and have tried everything I can think of but can't get it to work. Here's what I have: #include <iostream> using namespace std; class Test { public: void setName(char *name); char getName(); private: c...

Grouping associative array keys - in the same order

I have the following 2 arrays and would like to combine them. I'm more interested in the keys than their values. I'd like to take this $arr1 = array( 'tom' => "1", 'sally' => "20" // unique 'larry' => "2", 'kate' => "3", 'dave' => "23" //unique ); $arr2 = array( 'tom' => "11", 'larry' => "12", 'drummer' => "2",...

Delphi: SetLength() on argument of type "array of TObject"

I'm trying to resize an array of a certain class passed as an argument, e.g. procedure Resize(MyArray: Array of TObject); begin SetLength(MyArray, 100); end; However, this raises an error "E2008 Incompatible types". Is it true that you can't do this (I've seen rumors, but no official documentation) or am I doing something wrong? ...

Logo change with date script

Hi Folks, I just wondered if anybody can point me in the right direction: I'm looking to make a script whereby the logo on my site changes depending on the date; so for instance a haloween style one soon. I started off by having 2 arrays, 1 of start dates and 1 of end dates(not sure even if this is the best way!): <?php $start_dates...

Recursively sort array to levels

Hi, I've been working on a site that uses binary mlm system. Illustration here So I have a two tables in database, users anad relationships. There is ID and personal data columns in users. Relationships has 4 columns: ID, parentID, childID, pos. Where pos is either left or right. I have succesfully written a function that recursively...

Eclipse PDT: How do I get it to format my PHP arrays like VIM?

I've been struggling to get Eclipse to format my php arrays like vim indentation does. What eclipse does (press CTRL+SHIFT+F) <?php $array = array( 'key1' => 'value1', 'key2' => array( 'child_key1' => 'child_value1', 'child_key2' => 'child_value2', ), ); What vim does (press keys:gg=G) <?php $array = array( 'key1' => 'value1', '...

typedef in c and type equivalence

If I do this: typedef int x[10]; x a; Is it same as: int a[10]; ? ...

C array initialization via macro

Hi! Question's Background: void dash(int *n, char c) is to draw characters c separated by '+'. Parameter n is an array of ints, e.g. {1, 3, 2} and '-' for c should give "+-+---+--+", which works fine. To use dash I do {int f={1, 3, 2}; dash(f, '-');}, which makes the construct copy&pastable. The question itself: To avoid copy&pasting I ...

How to get random value out of an array

I have a an array called $ran = array(1,2,3,4); I need to get a random value out of this array and store it in a variable, how can I do this? ...

Vectorising operators in C#

I spend much of my time programming in R or MATLAB. These languages are typically used for manipulating arrays and matrices, and consequently, they have vectorised operators for addition, equality, etc. For example, in MATLAB, adding two arrays [1.2 3.4 5.6] + [9.87 6.54 3.21] returns an array of the same size ans = 11.07 ...

array looping strange behavior in php

I have an indexed array which I've generated from an associative array with this code $index_arr = array(); foreach($assoc_arr as $key => $val ){ $index_arr .= $val; } when I print it with print_r($index_arr); it works fine. But when I try to print it with foreach I get an error "Invalid argument supplied for foreach()" foreach($i...