arrays

PHP, passing each element in array into function without knowing how many elements in arrray?

This is stumping me.. I am writing components / library functions where it would be used for calling a lot of different functions, so I want it to make an array print out each variable to be passed into the function as an argument, like below but I am pretty sure that this isn't proper syntax.. thanks for any advice $myfunction = functi...

Write and extract array

Variable $total is an array(). print_r($total) gives: Array ( [01] => Array ( [title] => text [date] => date ) [02] => Array ( [title] => text [date] => date ) [03] => Array ( [title] => text [date] => date ) ) How to write this array to file.txt? And how to call created file later, so I can work with array inside it? Li...

Android Dynamic Array

Hello all, I am parsing an xml file through Android Pull Parser technique. first, have a look at the below xml file: <childs> <students> <name> hello </name> <address> xyz </address> </stdents> <students> <name> abc </name> <address> def </address> </stdents> </childs> Co...

Search in array

$total is an multi dimension array: Array ( [1] => Array ( [title] => Jake [date] => date ) [2] => Array ( [title] => John [date] => date ) [3] => Array ( [title] => Julia [date] => date ) ) How to search for [title] value and give as result ID of an array? If we search for Julia it should give 3 (ID is [3]). Thanks. ...

Duplicate Array key in Doctrine result

For a website i'm building I need to check wether a location has contracts, these locations can have contracts linked directly to them or when there part of a larger organisation also have contracts that are linked to the organisation. I am trying to use a DQL query to first check if there are contracts linked directly and then if there...

Getting all combinations of array items while preserving sequence - Ruby

Given an array of strings ["the" "cat" "sat" "on" "the" "mat"] I'm looking to get all combinations of items in sequence, from any starting position, e.g. ["the"] ["the" "cat"] ["the" "cat" "sat"] ... ["cat" "sat" "on" "the" "mat"] ["sat" "on" "the" "mat"] ["on" "the" "mat"] ... ["sat" "on"] ["sat" "on" "the"] Combinations out of t...

Associative Array : PHP/C vs Flex/Flash

In PHP an Associative Array keeps its order. // this will keep its order in PHP a['kiwis'] a['bananas'] a['potatoes'] a['peaches'] However in Flex it doesn't with a perfectly valid explanation. I really can't remember how C treats this problem but I am more leaned to believe it works like php as the Array has it's space pre-reserved i...

How can I check JavaScript arrays for empty strings?

I need to check if array contains at least one empty elements. If any of the one element is empty then it will return false. Example: var my_arr = new Array(); my_arr[0] = ""; my_arr[1] = " hi "; my_arr[2] = ""; The 0th and 2nd array elements are "empty". ...

Using Array with multiple reader threads + writer

Hi I am no sure about this .. Using an int[] array. If in my application, a thread A reads while a thread B writes into the same array element, will everything hold ? I'd rather not have a synchronized block on reading also - this is used in a web service, so I won't be able to service multiple clients in parallel. Thanks. Olivier ...

Is there better way to transpose a PHP 2D array?

According to the PHP Manual, calling array_map with a NULL callback causes it to perform a "zip" function, creating an array of arrays of parallel elements from the given arrays. For example: array_map(NULL,array(1,2,3),array('a','b','c')); yields array(array(1,'a'),array(2,'b'),array(3,'c')) This is also equivalent to transposing...

Initialize large two dimensional array in C++

I want to have static and constant two dimensional array inside a class. The array is relatively large, but I only want to initialize a few elements and others may be whatever compiler initializes them to. For example, if a class is defined like: class A { public: static int const test[10][10]; }; int const A::test[10][10] = { {0,...

SQL Server 2008 - how to get records that have a specific range of IDs

Hi guys In SQL Server 2008 I would like to create a stored procedure to select specific products, passing their IDs as argument. But I intend to bring as result a range of products. This range must have the informed productIds argument value (for example: 1 and 8 and 29 - that means, the range MUST have productId 1 and productId 8 and...

If Not String.Empty ignoring empty string - VB.NET

I have a array of strings and I am looping through them, but the string might be empty so I am trying this: For Each Component As String In Components If Component IsNot String.Empty Then 'Work your magic End If Next But if Component is an empty string the logic still fires. I've also tried If Component <> "" Then E...

Passing an nested arrays to asp.net mvc using jQuery's $.ajax

I am trying to pass a nested array to an asp.net mvc controller like this: var subgroups = []; subgroups [0] = [["A", "Y"], ["B", "Y"], ["C", "Y"]]; subgroups [1] = [["D", "Z"], ["E", "Z"], ["F", "Z"]]; $.ajax({ url: "<%= Url.Content("~/Controller/Action") %>", data: {...

Getting 'active' page to set nav tab

I want to be able to pull the name of the file and url I'm currently on, set two variables (filename, folder), and check it against an array. Depending what the values are, we set an 'active' class to that < li> to show the page is a part of that section. I've never really used arrays before, but I did a little research thinking they w...

$_POST multidemensional array looping

Hello! So I've created a form wich, by the post function, send me several values. $_POST[groups] sends me, using 4 different checkboxes values 1, 2, 4 and 8. $_POST[retailgroup] does the same, but only the values 1, 2 and 4. The problem is that I want these to add up together and then send the sum of the values to a MySQL table. I've man...

Getting Data from an Array

Unfortunately my last post was closed, so I try it again: I have an Array. I think it is multidimensional and I want to read out two values from it. This is a piece of it: d" ["rec_surname"]=> string(46) "-------------------bvvcb----------------------" ["rec_name"]=> string(52) "---------------------------vcbxcvb------------------" }...

Deep Copy with Array

Hi ... let's have this code : class A : ICloneable { public int x = 2; public A(int x) { this.x = x; } public A copy() { A a = new A(this.x); return a; } public object Clone() { A a = new A(this.x); return a; } } In Main Method : A[] Array1 =...

Fake array slicing operator: Make it shorter

Is there some innovative way to make the "print" shorter without too much confusion? And which of the "print" do you like most? define('_','_'); function _j($a, $b) { return $a._.$b; } // Output 0_0 print (0)._.(0); print _j(0,0); Update What I want to do is to have slice syntax that are in Python/Ruby into PHP eg. a[1:3] a[1,3...

from php to jquery

hi, i have array in php, and i need work with this array in jQuery. What best way send array( or variable ) from php to jQuery? Thanks ...