每个循环都没有从数组中获取值

每个循环都没有从数组中获取值

问题描述:

On using this code

echo "<pre>";
print_r($result);
echo "</pre>";

i get the following array

Array
(
    [0] => Array
        (
            [0] => S
            [1] => q
        )

    [1] => Array
        (
            [0] => C
            [1] => 
        )

    [2] => Array
        (
            [0] => G
            [1] => 3
        )

    [3] => Array
        (
            [0] => R
            [1] => 
        )

)

i wish to fetch the values and save them in database, but here i wish to save the values when both [0] and [1] has value in it. If any one of them does not hold a value then it should not be saved in database.

I tried to echo the result in [0] and [1] index place but not null value

foreach($result as $value){ 
    //echo $value['0'];    
    //echo $value['1']; 
   $result1 =  $value['0'];    
   $result2 = $value['1']; 
   if($result1!=""&&$result2!="")
     {
          //will run insert query here
     }
   }

can anyone tel how the desired result can be achieved??

使用此代码时 p>

  echo“&lt; pre&gt;  “; 
print_r($ result); 
echo”&lt; / pre&gt;“; 
  code>  pre> 
 
 

我得到以下数组 p> Array ( [0] =&gt;数组 ( [0] =&gt; S [1] =&gt; q ) [1] = &gt;数组 ( [0] =&gt; C [1] =&gt; ) [2] =&gt;数组 ( [0] =&gt; G \ n [1] =&gt; 3 ) [3] =&gt;数组 ( [0] =&gt; R [1] =&gt; ) ) code> pre>

我想获取值并将它们保存在数据库中,但是这里我希望保存值,当[0]和[1]都有值时 。 如果其中任何一个没有保存值,则不应将其保存在数据库中。 p>

我试图在[0]和[1]索引位置回显结果,但不是空值 p>

  foreach($ result as $ value){
 // echo $ value ['0'];  
 // echo $ value ['1'];  
 $ result1 = $ value ['0'];  
 $ result2 = $ value ['1'];  
 if($ result1!=“”&amp;&amp; $ result2!=“”)
 {
 //将在此处运行插入查询
} 
} 
  code>  pre> \  n 
 

任何人都可以告知如何实现所需的结果吗? p> div>

remove single quotes from array index, it requires only when associative array is there.

$result1 = $value[0];    
$result2 = $value[1]; 

Try this

foreach($result as $value){ 
//echo $value['0'];    
//echo $value['1']; 
$result1 =  $value[0];    
$result2 = $value[1]; 
if(!empty($result1) && !empty($result2))
 {
      //will run insert query here
 }
}