arrays

replace the same characters with different strings

Assuming I have a string $str = "abc*efg*hij*"; and an array $arr = array("123","456","789"); Now I want to replace the *s in $str with the elements in $arr according to the positions.The first * replaced with $arr[0],the second replaced with $arr[1] etc.I check the function str_replace,though it accepts arrays as parameters but I...

JS nested arrays

Hey, Im trying to make a nested array in JS var lines = new Array( "0"= new Array( 0['time']="10:00:00", 0['user']="User1", 0['content']="Line1", ), "1"= new Array( ...

What's in the memory of a dynamic array when used with SetLength in Delphi?

I have a dynamic array myArr. What is stored in the memory in myArr when we use SetLength on it? Is it '00'? Or undefined? SetLength allocates 16 bytes of memory for myArr in this case. myArr : array of byte; SetLength(myArr, 16); ...

MongoDB extract only the selected item in array

Suppose you have the following: // Document 1 { "shapes" : [ {"shape" : "square", "color" : "blue"}, {"shape" : "circle","color" : "red"} ] } // Document 2 { "shapes" : [ {"shape" : "square", "color" : "black"}, {"shape" : "circle", "color" : "green"} ] } do query: db.test.find({"shapes.color":"red"}, {"shapes.colo...

Sort an array which is partially sorted

I am trying to sort an array which has properties like it increases upto some extent then it starts decreasing, then increases and then decreases and so on. Is there any algorithm which can sort this in less then nlog(n) complexity by making use of it being partially ordered? array example = 14,19,34,56,36,22,20,7,45,56,50,32,31,45.......

how to get the value of array?

Hi, I want to get the value of productId and addressTypeID in this array: Array ( [0] => Array ( [entityId] => 7100122 [orderId] => 110631 [createDate] => 2010-10-19T05:40:00 [lastUpdateDate] => 2010-10-19T05:40:00 [deleted] => [products] => Array ( [Produ...

Interview question: three arrays and O(N*N)

Assume we have three arrays of length N which contain arbitrary numbers of type long. Then we are given a number M (of the same type) and our mission is to pick three numbers A, B and C one from each array (in other words A should be picked from first array, B from second one and C from third) so the sum A + B + C = M. Question: could w...

Bundle array of json/File/user-defined objects in Android.

how to bundle array of File objects or array of Json objects or array of user-defined objects in one activity and send it to another and how to access them correctly. ? Primitive types like string is quite easy with Intent in = new Intent(); Bundle bundle = new Bundle(); bundle.putString("name", "test"); in.putExtras(bundle); star...

In Perl, how can I convert arrays I read from database into a hash?

Basically, I'm querying a database and I need to convert the resultant array to a hash. I query the database as follows my $sth = $dbw->prepare($sql); while (@rows = $sth->fetchrow_array()) { ... ... } Now, I need to create a hash such that rows[0] is the key and rows[1],rows[2],rows[3] are the values. For each record read, a new h...

How does the Length() function in Delphi work?

In other languages like C++, you have to keep track of the array length yourself - how does Delphi know the length of my array? Is there an internal, hidden integer? Is it better, for performance-critical parts, to not use Length() but a direct integer managed by me? ...

Static const int not good enough for array size?

Hello! I’d like to do this: static const int size = 5; @interface Foo { char bar[size]; } But the compiler complains that “instance variables must have constant size”. Do I really have to #define the size, or is there a way to get it work with a regular constant? (I’d like the memory to be allocated statically, no malloc.) ...

Removing duplicates with array_unique

I created a image uploader which works by remote, so whenever a user enters a bunch of links, I want to prevent duplicate links being added so that the image isn't copied twice and is removed so it leaves the links to be unique without any duplicates. $break = explode("\n", $links); $count = count($break); $unique_images = array(); fo...

How to return string array using Pinvoke

My c/c++ skills are non-existent and there's some custom string array data that needs to be returned from an old C dll fyi - The C/C++ code can be modified as needed ...

Numpy.array indexing question

I am trying to create a 'mask' of a numpy.array by specifying certain criteria. Python even has nice syntax for something like this: >> A = numpy.array([1,2,3,4,5]) >> A > 3 array([False, False, False, True, True]) But if I have a list of criteria instead of a range: >> A = numpy.array([1,2,3,4,5]) >> crit = [1,3,5] I can't do this...

Passing array with unknown size to function

Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations. If I write the parameter list like that, the compiler will complain that it needs to know the size of the array at compile time. Is there a way to rewrite the parameter list so that I can pass an array with any size to the function? Edit...

ordering categories with php arrays

I have an array of categories: categories = computers, entertainment, products, graphics cards The array is sometimes returned in the wrong order BUT each category has a parent which exists in the SAME array. categories = products[parent=0], entertainment[parent=products], computers[parent=entertainment], graphics cards[parent=com...

Dynamically generating a dropdown using json data?

I have developed a script that receives json data from a php script using $.getJSON. The JSON data looks like '[{"options":"smart_exp"},{"options":"user_intf"},{"options":"blahblah"}] ' <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; <script type="text...

Get Smallest Difference between Adjacent Array Elements in a Sorted List

Hi, I have a sorted list of ratios, and I need to find a "bin size" that is small enough so that none of them overlap. To put it shortly, I need to do what the title says. If you want a little background, read on. I am working on a graphical experiment that deals with ratios and the ability of the eye to distinguish between these ratios...

Sort array by Alpha?

Code below takes a directory and creates an array of folder names appearing under the directory. How can order the folder names inside the array by alpha? function get_dirs($dir) { $array = array(); $d = dir($dir); while (false !== ($entry = $d->read())) { if($entry!='.' && $entry!='..') { $entry2 = $dir."/".$...

Sum of products of two arrays (dotproduct)

First off, I know my title can be formulated better, but my math classes are so far gone I can't remember the correct words anymore.. I need to do something like this (pseudo c#) int[] digits1 = new int[10]{0,1,2,3,4,5,6,7,8,9}; int[] digits2 = new int[10]{0,1,2,3,4,5,6,7,8,9}; int result = digits1*digits2 This would be the sum of th...