arrays

Declare Empty Array, populate and iterate troubles - PHP

I wrote a script to read the Netflix catalog and populate my DB. Everything worked fine as a web script (except for timeouts) so I shifted to calling directly form the console. I noticed a few oddities, like __construct() no longer being called (but that was easily remidied using the class name as a function. Now I can't get my arrays...

Multidimensional variable size array in C++

hi I want to do something like this: int op(string s1, string s2){ int x = s1.size(); int y = s2.size(); int matrix = new int[x][y] /* do stuff with matrix */ } For some reason I get the following errors: SuperString.cpp(69) : error C2540: non-constant expression as array bound SuperString.cpp(69) : error C2440: 'init...

Get empty slot with lowest index from an array

Hi, I am using .NET 3.5. What method of the Array class is best for returning a empty index in an array (which can then be used for populating). The Single/SingleOrDefault() methods look good, but if there is more than one empty slot, I want the first with the lowest index. EDIT: This is pretty easy with a loop, but I am looking at way...

Regex: Match words in sentence PHP

Hi, I have an array with words like $arr = array("go", "walk", ...) I would like to replace these words with links f they are matched in sentences. But it should be only if they match exactly (for example "walk" should match "Walk" or "walk!" but not also "walking") And the replacement should be a simple link like: < a href='#walk' >...

PHP - Loopless way to split a string into a multidimensional array

How do I split a string into a multidimensional array in PHP without loops? My string is in the format "A,5|B,3|C,8" ...

Can't get the keys in a database to parse as part of an array

I have an table in my database which so far has been great for storing stuff in more than one object. But i want to be able to transform it into a multi-object array thingy. Here is the data which is related to this new 'object' (in mysql): uid field value page:1 shop[2].location In Shops, Dundas Arcades,M...

How do I sort this array in JavaScript?

How do I sort this array? [ {id : 1, start : 60, end : 120}, {id : 2, start : 100, end : 240}, {id : 3, start : 700, end : 720} ] UPDATE: So if my array looks like this, can I sort it based on start value? [{ 1:{start : 60, end : 120}, 2:{start : 100, end : 240}, 3:{start : 700, end : 720} }] ...

How do I convert this object to an array in JavaScript?

How do I convert testObj to an array? function MinEvent(event, width, left){ this.start = event.start; this.end = event.end; this.width = width; this.top = event.start; this.left = left; } var testObj = {}; for (var j=0; j<eventLists.length; j++) { var eve = eventLists[j]; var event = new MinEvent(eventList[j], width, lef...

delete array element with foreach loop?

i want to loop an array with foreach to check if a value exist. and if it does, i want to delete that element. i have following code: foreach($display_related_tags as $tag_name) { if($tag_name == $found_tag['name']); // DELETE CODE } but i dont know how to delete the element once the value is found. ho...

array_key_exists, array_search, in_array doesnt apply to multidimensional array?

ive got an array like this: $display_related_tags[0][20] = 'text1'; $display_related_tags[1][21] = 'text2'; $display_related_tags[2][22] = 'text3'; i want to either check if value (text1) exists or if key (20) exists but the mentioned array functions just apply to one dimensional arrays. what are my alternatives without having to use...

sort an array and assign new numerical keys?

i have an array like this (after i unset some elements): $array[3] = 'apple'; $array[5] = 'pear'; $array[23] = 'banana'; which function do i use to sort them to: $array[0] = 'apple'; $array[1] = 'pear'; $array[2] = 'banana'; i tried some of the sort functions but it didnt work. ...

SQL Query to pull records from 2 tables related to each other - Table 2 depending upon Table 1

Hi all, I have 2 tables. Table 1 is 'articles' and Table 2 is 'article_categories'. When a user creates an article, it is stored into 'articles'. The user, while creating the article can select various categories under which this article can appear. Currently, an article can be selected to belong to anywhere from 10-25 categories(may be ...

php - recreate array?

I've "inherited" some data, which I'm trying to clean up. The array is from a database which, apparently, had no keys. The array itself, is pretty long, so I'm simplifying things for this post... [0] => Array ( [id] => 2 [uid] => 130 [eid] => 8 [ename] => Standard [...

How to properly calculate the amount of levels in an array?

I have a function that has to accept an array of points, or an array of array of points (a 2 or 3 dimensional array). I'm looking for an reliable way to detect whether it has 2 or 3 levels. The thing is, I cannot count on the keys of the arrays to do the checking, so this wont work: $levels = isset($array[0][0]) && is_array($array[0][0]...

Bash: add value to array without specifying a key

Is there a way to do something like PHPs $array[] = 'foo'; in bash vs doing: array[0] = 'foo' array[1] = 'bar' ...

PHP - How to loop through a associative array and get the key name?

My associative array: $arr = array( 1 => "Value1" 2 => "Value2" 10 => "Value10" ); Using the following code, $v is filled with $arr's values foreach($arr as $v){ echo($v); // Value1, Value2, Value10 } How do I get $arr's keys instead? foreach(.....){ echo($k); // 1, 2, 10 } ...

PHP: using variables in associative arrays?

Hi, it seems I missed something important about arrays in PHP. What's wrong with this: var $condition = array('Status.name = ' => 'PUBLISHED'); var $paginate = array('conditions' => $condition ); this works just fine: var $paginate = array('conditions' => array('Status.name = ' => 'PUBLISHED' )); ...

Sort ArrayBuffer[A] in scala?

I have an array in scala with the class "ArrayBuffer[Actor]", where Actor is a class that implements the "Ordered[Actor]" trait. How do I sort this array without coding it manually? I know there is an Object called Sorting, but it doesnt seem to work since ArrayBuffer doesn't implement/extend the right classes. How do I sort ArrayBuffe...

How do I make a class that can be indexed like a list in .net?

Classes in .net like List and Dictionary can be indexed directly, without mentioning a member, like this: Dim MyList as New List (of integer) ... MyList(5) 'get the sixth element MyList.Items(5) 'same thing How do I make a class that can be indexed like that? Dim c as New MyClass ... c(5) 'get the sixth whatever from c ...

Test ascending Javascript array of Date objects

I have a javascript array of Date objects, which I'd like to test for ascendingness. This is what I built, but I am kind of disappointed by it. Any suggestion? function isAscending(timeLine) { if (timeLine.length < 2) return true; for(var i=1; i < timeLine.length; i++) { if(timeLine[i-1] > timeLine[i]) return false; ...