php foreach loop failing to iterate when temporary variables are used I am trying to iterate through a simple php array, and have run into bizarre behavior that is causing iteration to terminate early. My php version is 5.6.3.  The following code prints the numbers 1 through 5, as expected...  $values = array(1, 2, 3, 4, 5);      foreach ($values as $v)         //$temp_variable = $v;         echo "v: " . "$v" . "\n";     However, if I uncomment the line with the temporary variable, like so, we only get one iteration!  $values = array(1, 2, 3, 4, 5);      foreach ($values as $v)         $temp_variable = $v;         echo "v: " . "$v" . "\n";     This seems extremely bizarre. How could the act of creating an unused temporary variable cause our loop to go off-the-rails? Any advice would be appreciated, thank you!
Why is it considered a bad practice to omit curly braces? Why does everyone tell me writing code like this is a bad practice?  if (foo)     Bar();  //or  for(int i = 0 i &lt; count; i++)     Bar(i);   My biggest argument for omitting the curly braces is that it can sometimes be twice as many lines with them. For example, here is some code to paint a glow effect for a label in C#.  using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor))) {     for (int x = 0; x &lt;= GlowAmount; x++)     {         for (int y = 0; y &lt;= GlowAmount; y++)         {             g.DrawString(Text, this.Font, br, new Point(IconOffset + x, y));         }      }  }  //versus using (Brush br = new SolidBrush(Color.FromArgb(15, GlowColor)))     for (int x = 0; x &lt;= GlowAmount; x++)         for (int y = 0; y &lt;= GlowAmount; y++)             g.DrawString(Text, this.Font, br, new Point(IconOffset + x, y));   You can also get the added benefit of chaining usings together without having to indent a million times.  using (Graphics g = Graphics.FromImage(bmp)) {     using (Brush brush = new SolidBrush(backgroundColor))     {         using (Pen pen = new Pen(Color.FromArgb(penColor)))         {             //do lots of work         }     }  } //versus using (Graphics g = Graphics.FromImage(bmp)) using (Brush brush = new SolidBrush(backgroundColor)) using (Pen pen = new Pen(Color.FromArgb(penColor))) {     //do lots of work }     The most common argument for curly braces revolves around maintance programming, and the problems that would ensue by inserting code between the original if statement and its intended result:  if (foo)     Bar();     Biz();     Questions:   Is it wrong to want to use the more compact syntax which the language offers? The people that design these languages are smart, I can't imagine they would put a feature which is always bad to use. Should we or Shouldn't we write code so the lowest common denominator can understand and have no problems working with it?  Is there another argument that I'm missing?
Setting the hostname: FQDN or short name? I've noticed that the "preferred" method of setting the system hostname is fundamentally different between Red Hat/CentOS and Debian/Ubuntu systems.   and the  say the hostname should be the FQDN:     HOSTNAME=&lt;value&gt;, where &lt;value&gt; should be the Fully Qualified Domain   Name (FQDN), such as hostname.example.com, but can be whatever   hostname is necessary.   The  is slightly more ambiguous:     Setup prompts you to supply a host name for this computer, either as a   fully-qualified domain name (FQDN) in the format hostname.domainname   or as a short host name in the format hostname.    says the hostname should not use the FQDN:     3.5.5. The hostname      The kernel maintains the system hostname. The init script in runlevel   S which is symlinked to "/etc/init.d/hostname.sh" sets the system   hostname at boot time (using the hostname command) to the name stored   in "/etc/hostname". This file should contain only the system hostname,   not a fully qualified domain name.   I haven't seen any specific recommendations from IBM about which to use, but  seems to have a preference.  My questions:   In a heterogeneous environment, is it better to use the vendor recommendation, or choose one and be consistent across all hosts? What software have you encountered which is sensitive to whether the hostname is set to the FQDN or short name? How do I execute a command-line program from C# and get back the STD OUT results? Specifically, I want to execute DIFF on two files that are programmatically selected and write the results to a text box. I'm using the built in Screen Sharing tool in El Capitan to control an iMac from a Macbook Pro in full screen mode. Everything works beautifully except that many special keys and gestures are intercepted by the local Mac and not sent to the shared Mac. Specifically:   Ctrl-Arrow (Desktops and Mission Control) F3 (Mission Control) F4 (LaunchPad) Three finger swipe (Switch between Desktops, Mission Control, Exposé) Two finger swipe from left side (Notification Center) Pinch with four fingers (Launchpad)   I can't find any way to switch between desktops on the remote machine other than manually opening the Mission Control app from the Finder or Dock. Disabling the gestures on the local machine doesn't help; they still don't get sent to the remote machine.  Is there any way to get special keys and gestures passed to the shared machine? Is it correct to use that/which in the relative clause when it is referring to the place as an object pronoun? If I calculate the median of a sufficiently large number of observations drawn from the same distribution, does the central limit theorem state that the distribution of medians will approximate a normal distribution? My understanding is that this is true with the means of a large number of samples, but is it also true with medians?  If not, what is the underlying distribution of sample medians? Proof of $a^n+b^n$ divisible by $a+b$ when $n$ is odd I read somewhere that     $(a^n - b^n)$         It is always divisible by $a-b$.   When $n$ is even it is also divisible by $a+b$.   When $n$ is odd it is not divisible by $a+b$.      and     $(a^n + b^n)$         It is never divisible by $a-b$.   When $n$ is odd it is divisible by $a+b$.   When $n$ is even it is not divisible by $a+b$.      I wonder what's the proof for this.  First postulate is clear. $(a-b)$ would or would not be a factor. Any light on others? How to merge records for query set We have a question related to a DB query :   CREATE TABLE `Action` (   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,   `emp_Id` int(10) unsigned NOT NULL,   `name` varchar(60) NOT NULL,   `updated_action_at` datetime(3) DEFAULT NULL,   `created_At` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,   `notes` varchar(400) DEFAULT NULL,   PRIMARY KEY (`id`),    KEY `action_empId_fk` (`emp_Id`),    CONSTRAINT `action_empId_fk` FOREIGN KEY (`emp_Id`) REFERENCES `Employee` (`id`) ON DELETE CASCADE,  ) ENGINE=InnoDB AUTO_INCREMENT=502004 DEFAULT CHARSET=latin1   CREATE TABLE `ActionAssignedTo` (   `action_Id` int(10) unsigned DEFAULT NULL,   `emp_Id` int(10) unsigned DEFAULT NULL,   KEY `actionassignedto_emp_id_foreign` (`emp_Id`),   KEY `actionassignedto_action_id_foreign` (`action_Id`),   CONSTRAINT `ActionAssignedTo_ibfk_1` FOREIGN KEY (`emp_Id`) REFERENCES `Employee` (`id`) ON DELETE CASCADE,   CONSTRAINT `ActionAssignedTo_ibfk_2` FOREIGN KEY (`action_Id`) REFERENCES `Action` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1  CREATE TABLE `Employee` (   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,   `vendor_Id` int(10) unsigned DEFAULT NULL,   `name` varchar(40) NOT NULL,   `mobile_Number` varchar(15) NOT NULL,   `active` tinyint(1) DEFAULT '1',   `updated_At` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,   `created_At` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,   PRIMARY KEY (`id`),   KEY `employee_vendor_id_foreign` (`vendor_Id`),   CONSTRAINT `employee_vendor_id_foreign` FOREIGN KEY (`vendor_Id`) REFERENCES `Vendor` (`vendor_Id`) ) ENGINE=InnoDB AUTO_INCREMENT=511 DEFAULT CHARSET=latin1   We want to find the action created by employee with Action.empId = 4 along with the list of Assignee (an action can be assigned to multiple people)  We have the following query :   Select     notes,             Action.id,             AssigneeName.name,             ActionAssignedTo.emp_Id  from       Employee inner join Action  on         (Action.emp_Id = Employee.id  and        Action.emp_Id in (select Employee.id                               from Employee                               where Employee.vendor_Id = 1)) inner      join ActionAssignedTo  on         Action.id =  ActionAssignedTo.action_Id inner join Employee as AssigneeName  on         ActionAssignedTo.emp_Id =  AssigneeName.id where      Action.emp_Id = 4   Now, lets say if Action with id = 10 was assigned to 2 people : John (empId : 2) And Jack (empId : 5) --> the above query returns following results :  (columns from the query)  notes                       | Action.id | AssigneeName.name | ActionAssignedTo.emp_Id 1. Finish Designing Queries | 10        | John              | 2 2. Finish Designing Queries | 10        | Jack              | 5   If we observe the above results the first 2 columns get repeated for the Assignees for SAME ACTION ID  --> is there a way we can merge them something like   1. Finish Designing Queries |10         | { John : 2  , Jack  : 5}   Basically records being merged into one. how to avoid number repeation by using random class in c#? trigger AccountReplicate on Account (after delete, after insert, after update) {     if ( trigger.isInsert ) {         for ( Account acc : trigger.new ) {             AccountOne__c ac = new AccountOne__c();             ac.Fax__c = acc.Fax;             ac.Phone__c = acc.Phone;             ac.Name =acc.Name;             insert ac;         }     }      if ( trigger.isUpdate ) {         integer  i = 0;         list&lt;AccountOne__c&gt; a2 = new list&lt;AccountOne__c&gt;([SELECT Id                                                         FROM AccountOne__c                                                         WHERE Name =: trigger.old[i].Name ]);         for ( AccountOne__c c1 : a2 ) {             c1.Name = trigger.new[i].name;             c1.Fax__C = trigger.new[i].Fax;             c1.Phone__C = trigger.new[i].Phone;             i++;         }         update a2;     } }   I tried bulk trigger for the update operation, but it's not working can anyone help me? How to close ports in Linux? I have some question in closing port, I think I got some strange things.  When I use execute  nmap --top-ports 10 192.168.1.1   it shows that 23/TCP port is open.  But when I execute  nmap --top-ports 10 localhost   it show that 23/tcp port is closed.  Which of them is true? I want to close this port on my whole system, how can I do it? Do superheroes/villains like Quicksilver or Flash with super speed get tired due to running? I mean a average human can run at his full speed for 15 to 20 mins before getting tired. Trained athletes can go on running for much more time without tiring out.  Do Superheroes like Quicksilver or Flash ever get tired due to excessive running? How to discover USB storage devices and writable CD/DVD drives (C#) How can I discover any USB storage devices and/or CD/DVD writers available at a given time (using C# .Net2.0).  I would like to present users with a choice of devices onto which a file can be stored for physically removal - i.e. not the hard drive. grep: memory exhausted Understanding ROC curve Tool to confirm Gaussian fit I have a series of (x1,y1) points.  I'm using a 3rd party software tool to which I feed these points. The tool then provides a mechanism for me to get back a series of (x2,y2) points that are on a Gaussian curve that has been fit to the data.  I'd like to confirm that the points I'm getting back are correct (because, frankly, sometimes they don't look like they are.)  What would be an easy on-line or Excel procedure that would allow me to enter the X1, Y1 series and then get back a series of X2, Y2 points, plot both series, and maybe even see the s.d.?  It's been 20+ years since I did any stats, so I'm just "cook-booking" this with no understanding of what I'm trying to do.  EDIT  The is a plot by wavelength, of intensity.  X-axis is the colors of a rainbow, in the familiar ROYGBIV order. The Y-axis is measured intensity of that particular color.   The help page from the vendor is here:    I call the library with each x1, y1 data point.  I then call the method above. I then call the library again with a series of x values (or maybe the x1 series itself), retrieving the y2 values on the fitted curve. I also retrieve the sd of the fit.  EDIT 2  Below is a link to an image of the dataset and Gaussian fit that has me concerned.  I think that the peak of the fitted curve is too low. Need clarification on the Draw 4 rule. - Player 1 lays down a Draw 4 Card and says the color is Red. - Player 2 does not have a Red card but has a Draw 4 Card. Can Player 2 lay down his Draw 4 Card and have Player 3 draw 8 cards? ASP.NET: Is there a way that I can simply pass a model into a view and render it to a string? How to mount electronics on a vehicle chassis safely I want to implement a control system I designed for a light electric motorbike. I would like to mount it as professionally as possible on the chassis. It consists of a power system pcb and a SAMC21 development board which I'll merge later once this all works properly. I have tried screwing it directly on the aluminium chassis but have found that shocks and vibrations from the horn disturbed the system or even destroyed it upon large shocks like a few hammer hits. Is there a specific way car and motorcycle manufacturers mount their electronics to make their system as robust as possible? Thank you for your help! Is there PvP in Diablo 3? How does it work? Correct position of "only" Which is grammatically correct?  I can only do so much in this time.  or  I can do only so much in this time.