arrays

PHP: get current array key?

$array = ( array('1231415'=>array('foo'=>'bar', 'test'=> 1)), array('32434'=>array('foo'=>'bar', 'test'=> '0')), array('123244'=>array('foo'=>'bar', 'test'=> 0)), array('193928'=>array('foo'=>'bar', 'test'=> 1)) ); I have an array that has (many) random keys, the ID number. I need to test each array within if 'test' = ...

How to implement such an associative array?

arr[key] = value; where key is a jQuery object and value is an array. ...

What could be the problem with this array?

This is the source $pData array I have: Array ( [code] => 105132 [globalImages] => Array ( [0] => 1148-1578-image_41ddeeef69eb94a8d9ccc1503d099810.jpg ) [envImages] => Array ( [0] => 1148-0-image_72e95c6424ec7bcd90994f1c0a3f4544.jpg ) [attribs] => Array ( ...

Bash arrays: Need help with white space

I'm trying to create an array in bash from a file with the following sample format: data, data, interesting data, data, more interesting The way I'm populating the arrays: read -r -a DATA1 <<< $(cat $FILE | awk -F, '{ print $1 }') read -r -a DATA2 <<< $(cat $FILE | awk -F, '{ print $2 }') read -r -a DATA3 <<< $(cat $FILE | awk -F, '{...

AS3: Splice two items in different places?

If I have an array private var temp:Array = [item1, item2, item3, item4, item5, item6, item7...etc]; and two variables for items in the array: private var firstPosition; private var secondPosition; Is there a way to remove BOTH items at once? Say, if firstPosition = item4, and secondPosition = item7...then firstPosition = temp[3...

"Cannot use string offset as an array" error

Hi folks, Can't figure what is wrong here. Read what folks are saying here: http://informationideas.com/news/2006/06/14/fatal-error-cannot-use-string-offset-as-an-array-in/ and here: http://stackoverflow.com/questions/1873970/cannot-use-string-offset-as-an-array-in-php I have print_r()-ed the actual values in $entries (coming from Go...

Sorting multidimensional array in PHP

Hi guys, I am currently creating a sorting method that consists of values from an mysql query. Here's a brief view of the array: Array ( [0] => Array ( ['id'] = 1; ['countries'] = 'EN,CH,SP'; ) [1] => Array ( ['id'] = 2; ...

Image format and unsigned char arrays

I'm developping imaging functions (yes I REALLY want to reinvent the wheel for various reasons). I'm copying bitmaps into unsigned char arrays but I'm having some problem with byte size versus image pixel format. for example a lot of images come as 24 bits per pixel for RGB representation so that's rather easy, every pixel has 3 unsign...

dynamic array IN struct, C

I have looked around but have been unable to find a solution to what must be a well asked question. Here is the code I have: #include <stdlib.h> struct my_struct { int n; char s[] }; int main() { struct my_struct ms; ms.s = malloc(sizeof(char*)*50); } and here is the error gcc gives me: error: invalid use of flexibl...

What is the best way to get unique elements of an array of activerecord objects based on attributes of the object?

In my application I am trying to display only unique elements of an array of activerecord objects(loss_reports) based on two attributes of a loss_report. Schema class Agent < ActiveRecord::Base has_many :loss_reports, :through => policy end class LossReport < ActiveRecord::Base belongs_to :agent end I first tried to overr...

Ways To Marshal A Pointer of Array of Struct

I'm calling functions from C++ that returns a pointer to an array of struct and I'm having problems since I'm new to this operation/implementation. My C++ codes: // My C++ Structs typedef struct _MainData { double dCount; DataS1 *DS1; int iCount1; DataS2 *DS2; int iCount2; }MainData...

How to split the array keyword value separated by commas in PHP?

Hello! I have an array in $_POST: Array ( [tags] => Javascript,PHP,Java,C++,Python) How can i convert this Array into Array like this: Array ( [tag1] => Javascript [tag2] => PHP [tag3] => Java [tag4] => C++ [tag5] => Python) I guess i need to use regexp to remove the commas and do split in "foreach as".. But i'm so newbie in PHP....

How to post a array with $.post ?

Here is my array: arr[0]='A'; arr[1]='B'; .... I tried to post it this way: $.post('data.php',arr,function() { }); But fails to work as expected. ...

str_replace string in array number auto increasing

Hi All, what we can do to remove page=2& From: "page=2&param1=value1&param2=value2" or "param1=value1&page=2&param2=value2". become: "param1=value1&param2=value2" or "param1=value1&param2=value2". in case of page=2, 2 is any natural no. i.e. (0 to 32000). Regards, ...

How can I divide a Perl array into smaller arrays?

Is there any Perl equivalent for php's array_chunk()? I'm trying to divide a large array into several smaller ones. Thanks in advance. ...

shouldn't PHP array recursion throw an error?

This is the test and the response I get. I think this could be problematic and should throw an error or a notice but I cannot understand why is tolerated. <?php $test = array( 0 => 'test', 1=> &$test ); var_dump( $test ); // array(2) { [0]=> string(4) "test" [1]=> &array(2) { [0]=> string(4) "test" [1]=> &array(2) { [0]=> s...

Array in Object passed by value?

Maybe I am overlooking something, but I stumbled across this: $employees = new stdClass(); $employee_id = 5; $employee = array(); $employee["id"] = $employee_id; $employee["name"] = "John; $employees->$employee_id = $employee; Now I want to change the employee Name: $employee = $employees->$employee_id; $employee["name"] = "Tom"; ...

Using array of chars as an array of long ints

On my AVR I have an array of chars that hold color intensity information in the form of {R,G,B,x,R,G,B,x,...} (x being an unused byte). Is there any simple way to write a long int (32-bits) to char myArray[4*LIGHTS] so I can write a 0x00BBGGRR number easily? My typecasting is rough, and I'm not sure how to write it. I'm guessing jus...

C# Cast Entire Array?

I see this Array.ConvertAll method, but it requires a Converter as an argument. I don't see why I need a converter, when I've already defined an implicit one in my class: public static implicit operator Vec2(PointF p) { return new Vec2(p.X, p.Y); } I'm trying to cast an array of PointFs to an array of Vec2s. Is the...

efficiant System.arraycopy on multidimensional arrays

I'm aware that a common performance refactoring is to replace simple fors by System.arraycopy. I want to ask about: 1) when exactly does system.arraycopy begin to make sense (considering its a native method call). Does compying small things say, < 32 have any advantage? 2) Is it my impression, or is it not simply possible to copy (effi...