loops

Retrieve array key passed on value PHP

…衆ロ難τιáo~ 提交于 2020-01-17 03:26:06
问题 I have the following array $group= array( [0] => 'apple', [1] => 'orange', [2] => 'gorilla' ); I run the array group through an for each function and when the loop hits values of gorilla I want it to spit out the index of gorilla foreach ($group as $key) { if ($key == gorilla){ echo //<------ the index of gorilla } } 回答1: You can use array_search function to get the key for specified value: $key = array_search('gorilla', $group); 回答2: foreach( $group as $index => $value) { if ($value ==

Variable “i” not displaying in javascript for loop

女生的网名这么多〃 提交于 2020-01-17 02:55:47
问题 I am trying to do some for loop practice and apply the blue color style to all "listing" class with a click event. In addition to that, i also wanted to print the value of "i" in every loop. Can anyone point out what im missing in the code please. Thank you Here is my code: function changeClass(){ for (i=0;i<3;i++) { var list = document.getElementsByClassName("listing")[i]; list.style.color = "blue"; var values = document.getElementsByClassName("value"); document.write(i); } } document

Modify WordPress loop to output all images in a post with thumbnails included in the image tag?

拥有回忆 提交于 2020-01-17 02:55:08
问题 This question requires some php, some jquery, and some general programming logic. With generous help in previous questions here, I have built a script that scans WordPress posts for image attachments and, if it finds any, moves these to list items in a newly created <ul> outside of the post. The reason for this is to make the images available to a slider (RoyalSlider) that I am hard-coding into the theme (I do not want to use the WP plugin version for several reasons). You can see the site I

How to output to console in real time in Javascript?

一世执手 提交于 2020-01-17 02:20:54
问题 In Javascript, when you write a piece of code like the one below, it seems like the computer will first complete the entire loop 100 000 times (which can take a second or two) and THEN dump all 100 000 lines in the console in one shot. How can I make it so that the computer will update the console one line at a time, with each pass thru the loop? To clarify, I would like to, in effect, be able to see what the computer is doing AS it is doing it, and not once it has finished doing it. for (var

Scanf skipped in loop (Hangman)

有些话、适合烂在心里 提交于 2020-01-17 01:15:55
问题 This program essentially asks for a secret string, then asks a user to repeatedly guess single chars of that string until he guesses it all. It works however every second time the while loop is run it skips user input for the guessed char. How do I fix this? int main(){ char guess; char test2 [50]; char * s = test2; char output [50]; char * t = output; printf("Enter the secret string:\n"); fgets(test2, 50, stdin); for (int i=0;i<49;i++){ //fills ouput with _ spaces *(output +i)='_'; while

Exporting movie from matlab

一个人想着一个人 提交于 2020-01-16 20:29:31
问题 I am trying to make a movie in matlab. for i=1:runs; for k=1:NO_TIMES B = 0; [conf dom_size] = conf_update_massmedia(time(k),conf); shortconf=conf(1:N); for j=1:N; sigma(j,1:N) = conf(1+(j-1)*N:j*N); end figure(1) imagesc(sigma); colorbar; set(gcf,'PaperPositionMode','auto'); F(k)=getframe(gcf); end end movie2avi(F,'B=0.avi','Compression','none') So my problem is that i only get a movie from the last run of the loop, i have tried to move the code for the figure around, but nothing seems to

how to run chisq.test in loops using apply

好久不见. 提交于 2020-01-16 19:14:19
问题 I am a newbie of R. Due to the need of my project, I need to do Chisq test for hundred thousand entries. I learned by myself for a few days and write some code for runing chisq.test in loops. codes: the.data = read.table ("test_chisq_allelefrq.txt", header=T, sep="\t",row.names=1) p=c() ID=c() for (i in 1:nrow(the.data)) { data.row = the.data [i,] data.matrix = matrix ( c(data.row$cohort_1_AA, data.row$cohort_1_AB, data.row$cohort_1_BB, data.row$cohort_2_AA, data.row$cohort_2_AB, data.row

SQLite Flow Constructs in SQL?

為{幸葍}努か 提交于 2020-01-16 19:03:49
问题 With MSSQL, I can mix in case, if...then, and while constructs in my SQL code. Is anything similar available for SQLite? I have not seen anything on "mixing procedurally" with SQLite, anywhere. Thanks. 回答1: SQLite doesn't have any loop syntax - FOR or WHILE . CASE statements are supported rather than IF. 来源: https://stackoverflow.com/questions/1885702/sqlite-flow-constructs-in-sql

JavaScript closure inside loops – simple practical example

Deadly 提交于 2020-01-16 16:29:07
问题 var funcs = []; // let's create 3 functions for (var i = 0; i < 3; i++) { // and store them in funcs funcs[i] = function() { // each should log its value. console.log("My value: " + i); }; } for (var j = 0; j < 3; j++) { // and now let's run each one to see funcs[j](); } It outputs this: My value: 3 My value: 3 My value: 3 Whereas I'd like it to output: My value: 0 My value: 1 My value: 2 The same problem occurs when the delay in running the function is caused by using event listeners: var

Using wx.CallLater in wxPython

佐手、 提交于 2020-01-16 16:16:45
问题 I'm trying to make an object that handles basic time related functions. I want it so when any of the attributes (e.g. self.Time ) are referenced they are up to date. However, for some reason wx.CallLater(1000, self.Tick) doesn't seem to be updating the attributes. It will only print self.Time once, as opposed to every second (like I want it to). How would I go about getting the behavior I desire? Should I use something besides wx.CallLater(1000, self.Tick) ? Snippet : import wx, re, time,