Skip to main content

Posts

Showing posts with the label arrays

Java Variable References when using Lists

Just a thought question here. In C++, I could do the following: vector<vector<string> > data; // add data into data //.. data[0].push_back( "somedata" ); And I would expect somedata to get written to the vector array because the [] notation gives me access to the object by reference. What about in Java? If I: List<List<String>> data = new ArrayList<List<String>>(); // add data into data //.. data.get(0).add( "somedata" ); Would this actually write somedata into the data object? Or would it create a new copy of the element at data(0), add somedata to that, and then that object disappears into GC sometime down the line?

Creating 9 subarrays from a 9x9 2d array java

Hello I need help creating 9 sub arrays of 3x3 dimensions from a 9x9 array. I've seen that stackOverflow had a similar question already asked but unfortunately it was in c++. Can anyone point me in the right direction of how to create a a sub array. Edit: had aa similar changed to had a similar public static void Validate(final int[][] sudokuBoard) { int width = sudokuBoard[0].length; int height = sudokuBoard.length; for(int i = 0; i < width; i++) if(!IsValidRow(sudokuBoard, i, width)) { System.out.print("(Row)" + i + " Error Detected \n"); //Do something - The row has repetitions } for(int j = 0; j < height; j++) if(!IsValidColumn(sudokuBoard, j, height)) { System.out.print(" (Column)" + j + " Error Detected \n"); //Do something - The columns has repetitions } // for(int i=0; i<3; i++) // if(!isBlock1Valid(sudokuB

Splitting a CSV into an object with javascript/jquery

I have an ordered array which looks like this:- [-0.0020057306590257895, 50, 0.09598853868194843, 50, 0.19398280802292264, 49.99999999999999, 0.2919770773638969, 50] What I would like to do is the following: Take each 'odd' entry and make it the 'key index in an object, which can be achieved by rounding the value and multiplying by 10 e.g. (Math.round(-0.0020057306590257895 * 10) should be index 0 and Math.round(0.09598853868194843 * 10) should be index 1 etc) Take the 'even' values and make them the corresponding values in the object. So... The above CSV file should return the following object:- { 0: 50, 1: 50, 2: 49.99999999999999, 3: 50 } Does anyone one know how I can parse this CSV to produce the required array using either jQuery or plain javascript?

How can i store the values of array_count_values in array of object?

i have array like below which is sorted by array_count_values function, Array ( [Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV] => 3 [Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 2pmADV] => 2 [Session #4: Tues July 12th - Fri July 22nd (9-2:00PM)#1 only: 1:30pmADV] => 2 ) i need to convert this array into array of object like below, stdClass Object ( [Itemname] => Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV [Quantity] => 3 ) stdClass Object ( [Itemname] => Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 2pmADV [Quantity] => 2 ) stdClass Object ( [Itemname] => Session #4: Tues July 12th - Fri July 22nd (9-2:00PM)#1 only: 1:30pmADV [Quantity] => 2 ) how can i do this?

Remove the parent array key in PHP?

I have an array structure like this : Array ( [donate] => Array ( [amount_other] => 222 [pay_method] => Array ( [5] => Array ( [first_name] => sam [last_name] => indi [cc_type] => mc [cc_number] => 5123456789012346 [cc_ccv2] => 111 [cc_exp_month] => 10 [cc_exp_year] => 20 ) ) [notes] => Test comment. ) ) I want to remove key [5] from the array, so that the new array becomes : Array ( [donate] => Array ( [amount_other] => 222 [pay_method] => Array ( [first_name] => sam [last_name] => indi [cc_type] => mc [cc_number] => 5123456789012346

How can I add a variable to an array?

How can I add a variable to an array? Let say I have variable named $new_values : $new_values=",543,432,888" And now I would like to add $new_values to function. I tried in that way: phpfunction1(array(114,763 .$new_values. ), $test); but I got an error Parse error: syntax error, unexpected T_VARIABLE, expecting ')' How my code should look if I would like to have array(114,763,543,432,888) ?

Gathering segmented data via jQuery with FOR loops

Here's my code (what I'm stuck on is after the jump) <script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script type="text/javascript"> var countThisMany = 4; //how many data-id's I want to count per "section" of images var finalString = ""; //blank var to be used later, must be defined here. </script> <img src="foo.jpg" data-id="id1" data-item="1" /> // just a bunch <img src="foo.jpg" data-id="id2" data-item="2" /> // of images with <img src="foo.jpg" data-id="id3" data-item="3" /> // data-* usage to <img src="foo.jpg" data-id="id4" data-item="4" /> // store two bits <img src="foo.jpg" data-id="id5" data-item="5" /> // of information &l

Trouble with displaying JSON array

could you please help me figure out why I'm getting "undefined" instead of the value. As it is plain to see I'm having trouble getting the data from the array, in firebug I get this as a response.... {"status":"success", "response":[ {"email": {"email":"xxxxx@iing.mxl.uabc.mx", "valid":"1", "reason":null, "confirmed_at":"0000-00-00 00:00:00", "contact_email":"1", "login_email":"1", "users_id":"6375"}, "history":[ {"contactRole":"Non Classified Lead with History", "contactProject":"2082", "contactBrand":"B"}, {"contactRole":"co Author", "contactProject":"32", "con

How can I check if an array contains a specific value in php?

I have an array of data created by a form that and I would like find out if it contains a specific value and let the user know that it is there. This is my array: Array ( [0] => kitchen [1] => bedroom [2] => living_room [3] => dining_room) and I would like do something like: if(Array contains 'kitchen') {echo 'this array contains kitchen';} What is the best way to do the above???

How to merge two arrays [closed]

Possible Duplicate: How to merge these two arrays? I've got two arrays array( '1' => 'string 1', '2' => 'string 2', '3' => 'string 3' ) array( 'a' => 'string a', 'b' => 'string b', 'c' => 'string c' ) What do I have to do to get this result: array( '1' => 'string 1', '2' => 'string 2', '3' => 'string 3', 'a' => 'string a', 'b' => 'string b', 'c' => 'string c' ) Will a simple $result = array_merge($array1, $array2) suffice or just glue them together with PHP $result = $array1 . $array2

How to use keywords to filter a JSON array object?

I am trying to find a way to take an array of keywords that are user createda and filter a JSON array, and have the results appended to the screen. Below is the actual code I am using. var keywords= []; var interval = ""; var pointer = ''; var scroll = document.getElementById("tail_print"); $("#filter_button").click( function(){ var id = $("#filter_box").val(); if(id == "--Text--" || id == ""){ alert("Please enter text before searching."); }else{ keywords.push(id); $("#keywords-row").append("<td><img src=\"images/delete.png\" class=\"delete_filter\" /> " + id + "</td>"); } } ); $(".delete_filter").click( function(){ ($(this)).remove(); } ); function startTail(){ clearInterval(interval); interval = setInterval( function(){ $.getJSON("ajax.php?function=tail&pointer=" + p

Filter array in PHP using keywords?

What could I add to the following code to filter the returned results using keywords in an array? The code that send the keywords, and made the funciton call is in Javasript. The code below opens a file, takes a pointer using a request, opens the file finds the pointer, and retrieves all log lines from the pointer to the end of the file. Then it formats it into a JSON object and sends back to Javacript. function tail(){ $keywords = json_decode($_REQUEST['keywords']); $file = "/path/to/the/log.log"; $handle = fopen($file, "r"); clearstatcache(); if ($_REQUEST['pointer'] == '') { fseek($handle, -1024, SEEK_END); } else { fseek($handle, $_REQUEST['pointer']); } while ($buffer = fgets($handle)) { $log .= $buffer . "<br />\n"; } $output = array("pointer" => ftell($handle), "log" => $log); fclose($handle); echo json_