arrays

How can I do this with PHP arrays?

<?PHP $signup_errors = array(); $signup_errors['captcha'] = 'test 1'; $signup_errors['something'] = 'test 2'; $signup_errors['another'] = 'test 3'; $signup_errors['getthepoint'] = 'test 4'; //this would work if (isset($signup_errors) && in_array('test 4', $signup_errors)){ echo 'it works'; } //However I need something like this to...

Merging File and Post data in PHP

At work I've been dealing with some complex forms (publish pages of Symphony) that contain multiple image upload fields. I need a way to quickly merge $_FILES with $_POST, unfortunately you cannot simply merge the two with array_merge because they don't follow the same structure. Basically if you have $_POST[a][b] it would be $_FILES[a]...

Transform an array to several sql statements

Hi, I have a array that looks like this Array ( [provider] => Array ( [id] => provider1 [distribuitor] => Array ( [0] => Array ( [name] => distribuitor1 [machines] => Array ( ...

Is int *array[32] a pointer to an array of 32 ints, or an array of 32 pointers to int? Does it matter?

If I write int *columns[32]; am I defining an array with 32 pointers to ints? Or is it a pointer to an array of 32 ints? How do I differentiate between the two? Is there a difference? ...

VBSCRIPT arrays keys

Hello I'm fairly new to vbscript and I'm struggling a little as I'm more familiar with Javascript. Can someone please give me a hand? Does vbscript allow the use of named array keys like I have in my example below? For example I have: Dim result(3) result(age) = 60 result(firstname) = "Tony" result(height) = 187 result(w...

Shift elements in string array to left to fill 'holes'

I have a list of names and phone numbers like so: var phonelist = List<string[]> { new string[] {"Bill", "1234", "12345", "12314" }, new string[] {"Bob", "", "12345", "12314" }, new string[] {"Chris", "", "", "12314" }, new string[] {"Dave", "1234", "", "12314" }, new string[] {"Andy", "1234", "12345", "" }, } ...

PHP arrays - simple query

Ok I know this is simple, in fact damn simple, I did this in the last project about a week ago, but I don't know why it has skipped off my head. Input: $word = "stack"; What I want to do is: $array = array("s", "t", "a", "c", "k"); Any help will be appreciated! ...

How to convert a String into an array of Strings containing one character each

I have a small problem here.I need to convert a string read from console into each character of string. For example string: "aabbab" I want to this string into array of string.How would I do that? ...

How are array and pointer types handled internally in C compilers? ( int *a; vs. int a[]; )

I need a language lawyer with authoritative sources. Take a look at the following test program which compiles cleanly under gcc: #include <stdio.h> void foo(int *a) { a[98] = 0xFEADFACE; } void bar(int b[]) { *(b+498) = 0xFEADFACE; } int main(int argc, char **argv) { int a[100], b[500], *a_p; *(a+99) = 0xDEADBEEF; *(b+499...

What's the fastest way to populate an array with numbers in PHP?

What's the fastest way to populate an array with the numbers 1-100 in PHP? I want to avoid doing something like this: $numbers = ''; for($var i = 0; i <= 100; $i++) { $numbers = $i . ','; } $numberArray = $numbers.split(','); It seems long and tedious, is there a faster way? ...

How to expand JavaScript Array with another Array?

There doesn't seem to be a way to expand a JavaScript Array with another Array, i.e. to emulate Python's extend method. What I want to achieve is the following: >>> a = [1, 2] [1, 2] >>> b = [3, 4, 5] [3, 4, 5] >>> SOMETHING HERE >>> a [1, 2, 3, 4, 5] I know there's a a.concat(b) method, but it creates a new array instead of simply e...

Array index limit in C

on linux, with 16 GB of ram, why would the following segfault: #include <stdlib.h> #define N 44000 int main(void) { long width = N*2 - 1; int * c = (int *) calloc(width*N, sizeof(int)); c[N/2] = 1; return 0; } According to gdb the problem is from c[N/2] = 1 , but I do not know the reason thanks ...

Saving an Array to a Text file in Java

I'm trying to print the values of an int array to a local file. However, I can't seem to find a way to print the integers out in their standard form (1,2,3) instead of a heap address: ([I@1befab0) My code fragment is below: PrintWriter pr = new PrintWriter("file"); for (int i=0; i<views.length ; i++){ pr.pr...

How can I check that an array key exist if the array does not exist in PHP

I am in a bind, multiple times on a page for different form items, I insert a css div class into a form item ONLY if an error_array key exists, this is how I highlight a form item that has an error in it. Works, great if I have an error because then my error array is set, problem is before an error is set, it tries to look for an array ...

Initializing static array of strings (C++)?

I can't for the life of me figure out how to do this properly. I have a class that needs to store some constants (text that corresponds to values in an enum type) - I have it declared like this (publicly) in my class: const static char* enumText[]; And I'm trying to initialize it like this: const char* MyClass::enumText[] = { "A", "...

Getting XML keys and values easily in PHP

I'm working with various XML inputs and outputs and simply want to grab the keys and values like you can with an array. Is there a simple function that can convert xml to an array or access the keys and values or am I going about this completely the wrong way? <?php $xmlstr = " <key> <parent1> <child1>val1</child1> <child...

function to take array of arbitrary type in c#

I've made a function that processes an array of objects, process(Object[]). It works on any type including integers and floats so long as you box each element first. I'd like the function to take unboxed elements aswell, if only to box it itself before processing. How do I do that? I could wrap with a few functions like process(int[]) a...

How do I refresh an array in a foreach loop?

I am writing a Perl script to do some mathematical operations on a hash. This hash contains the values as given in the sample below. I have written the code below. If I execute this code for an array value separately without using a foreach loop, the output is fine. But if I run this using a foreach loop on the array values, the sum for...

Convert linq query to string array - C#

What is the most efficient way of converting a single column linq query to a string array? private string[] WordList() { DataContext db = new DataContext(); var list = from x in db.Words orderby x.Word ascending select new { x.Word }; // return string array here } ...

How might I find the largest number contained in a JavaScript array?

I have a simple JavaScript Array object containing a few numbers. [267, 306, 108] Is there a function that would find the largest number in this array? ...