Click here to Skip to main content
14,843,569 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i tried to to print into the following format
(1,2)
(3,4)
but
it shows
(1,2)
(,3)
(,4)

here is my code
php
$z1=array(1,2,3,4);
  $temp=" ";
   foreach($z1 as $y)
      {
          if($temp !==" ")
          {


          print_r("(".$temp.",".$y.")");
          $temp = "";

          echo"<br>";
          }
          else
         {
              $temp=$y;
          }
      }
Posted

Quote:
print_r("(".$temp.",".$y.")");
$temp = "";

the last line should be
$temp = " ";


That is, you missed a blank.
   
v2
Take the space out of $temp,

You have $temp = " ";

Change to $temp = "";

and

if($temp !=="")

I gave you that code and it was working your not even trying man,

I also point out the reason that happened is cause in your if block your setting $temp to $temp = ""; See no space.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900