title: Php If Statement Ignore first condition and automatically population Alert Window
body: <p>I am trying to generate the alert window if condition is already set. But when the add button is click,  the code automatically generate the Alert Window.  I am expecting that the window prompt should happen after the item is already added to the cart.  In which,  if the ID exist in the array, the window prompt is populated upon the session being set.  Can someone help me identify what I may be doing wrong with the code shown below?</p>
  <pre><code>                            
                              if (isset($_SESSION['cart'])) {
  
                                   $item_array_id = array_column($_SESSION['cart'], 'id'); //Check if item is already added to cart. 
  
                                   if (in_array($row['id'], $item_array_id)){//execute if item is already added to cart. 
                                      echo &quot;&lt;script&gt; alert('Product is already added to cart');&lt;/script&gt;&quot;;
                                      echo &quot;&lt;script&gt; alert('window.location='index.php'&lt;/script&gt;&quot;;
                                  }
                             }
                                                              
                          }else{
                                  $item_array = array('id' =&gt; $row['id']); 
                                  $_SESSION ['cart'][0] = $item_array;
                          }
  </code></pre>