arrays

Pointer to Array of Struct

struct bop { char fullname[ strSize ]; char title[ strSize ]; char bopname[ strSize ]; int preference; }; int main() { bop *pn = new bop[ 3 ]; Is there a way to initialize the char array members all at once? Edit: I know I can use string or vector but I just wanted to know out of curiosity. ...

How to loop on $_GET array and escape all its variables?

Hi, How to mysql real escape string all $_GET contents? Thanks ...

Search inside arrays, count, find duplicates, compare

Several HOW TO questions about simple and multidimensional arrays: 1) How to search in simple and multi arrays? 2) How to count number of search results? 3) How to catch duplicates inside: 3.1 multidimensional array? 3.2 simple array? 3.3 in array's search results? 3.4 and remove them? 4) How to compare two arrays (multidime...

Recursive function for getters/setters?

I am looking for an algorithm in Java that creates an object thats attributes are set to the first not-null value of a string of objects. Consider this array (I will use JSON syntax to represent the array for the sake of simplicity): { "objects": [ { "id": 1, "val1": null, "val2": null, ...

Get total number of each unique value in an array?

Okay, so I've got an array that has a ton of random numbers in it, like this... $array = array(134, 12, 54, 134, 22, 22, 1, 9, 45, 45, 12, 134, 45, 134); What I need to do, is find out what numbers are contained in my array, and if a number is duplicated in the array, I'd like to know how many times that number is found within the arr...

what is a good method to sanitize the whole $_POST array in php?

I have a form with a lot of variables which is then sending an email, rather than sanitizing each $_POST value with filter_var($_POST['var'], FILTER_SANITIZE_STRING); I was after a more simple piece of code. I came up with the below, which seems to work as I believe the default action is FILTER_SANITIZE_STRING, but I was just wondering ...

Moving a element of a ArrayList to the Front while keeping the order C#

Say i have a Array like so, The, Quick, Brown, Fox, Jumps and i need to move/shift one of the elements to the front so it looks like this Brown, Fox, Jumps, The, Quick How can one sort an array like a revolving door? by moving one element and having the rest follow behind? Is there an easy method or should i just copy/loop/slic...

Reference to an address?

#include<stdio.h> int main(void) { int arr[3]={1,2,3}; return 0; } Now what will *(&arr) give me and why? I want a detailed explanation. Don't just tell me how * and & cancel out :P I want to know how the compiler interprets this expression to give the desired result. ...

increment float array ptr

I am trying to move the float array ptr 256 "units" from the start so (256 * 4 bytes) for floats. I am receiving a compile time error. long new_capture_length = 4096; long step_size = 256; float data[new_capture_length]; data+=step_size; error: invalid operands to binary + (have ‘float[(long unsigned int)(new_capture_length)]’ and ‘fl...

view contents of large array?

I have a very large array I need to check for debugging purposes, problem is it crashes firebug and the like if I try to view the data. Is there a way I can dump the array to a text file or something? ...

how to detect if an array isnt empty?

I am trying to detect if an array isn't empty in order to be able to do a certain call. I tried using if (![array ==nil]) however that doesn't compile. I'm sure there is a really easy explanation to this. Update If array is empty I want to do this: array = [[NSMutableArray alloc]init]; If it has an object I want to do this: array =...

passing while() array to a variable out of while() in php

suppose i have a query $array = array(); $sql = mysql_query("SELECT * FROM table"); while($row=mysql_fetch_array($sql)){ $data = $row['data']; } $array = $data; Now how can i get that each $data values out of while in an array() i.e $array ...

How to check if "set" in c

If I allocate a C array like this: int array[ 5 ]; Then, set only one object: array[ 0 ] = 7; How can I check whether all the other keys ( array[1], array[2], …) are storing a value? (In this case, of course, they aren't.) Is there a function like PHP's isset()? if ( isset(array[ 1 ]) ) ... ...

Is there a guarantee as to the size of a class that contains an array?

Given: template <int N> struct val2size { char placeholder[N]; }; Is there any guarantee that sizeof(val2size<N>) == N? ...

About creating an array at php

Hi, I am having trouble at creating a specific array. What i want is to pull the info for my members (from mysql database) and then store them to an array. The array should be like this: $members = array( 'John' => array('avatar' => '/images/avatar/ji.jpg', 'country' => 'uk.'), 'Nick' => array('avatar' => '/images/avatar/nick.jpg', 'co...

Best way to sort an array with the longest strings in the middle and the shortest at the beginning and end

Just for fun really. I was curious of the best way to do this. ...

Getting Function to take value in array as an input JAVA

I am trying to get a function in JAVA to take a value in an array as input. Here is my attempt: public static void main(String[]args) { int [] a = new int [4]; a[0]=6; a[1]=7; a[2]=5; a[3]=2; int g = 11; System.out.println calc(a[0], 11); } public static int calc(a[], int g) I am doing this before running a...

How to merge array using PHP?

Hi i have 3 array Date Array array( 0 => array("date_1" => "06-09-2010"), 1 => array("date_2" => "07-09-2010"), 2 => array("date_3" => "08-09-2010") ) Day Array array( 0 => array("day_1" => "Monday"), 1 => array("day_2" => "Tuesday"), 2 => array("day_3" => "Wednesday") ) Period Array array( 0 => array("per...

How to explode array and assign chunks to respective checkbox fields?

Hi, Following situation: I stored a checkbox array with implode in a mysql table field. Now, in order to update the checkboxes, I want to read the table field content, explode it into its parts and assign it to the respective checkboxes. So far I managed to read out and explode the table field content into different chunks, my difficul...

Write very large array to file in PHP

I've got a client with a Magento shop. They are creating a txt file to upload to googlebase, which contains all of their products, but due to the quantity of products (20k), the script bombs out once it's taken up about 1gb. It's being run via cron. Is there a way to either zip or segment the array, or write it to the file as it's creat...