du16178 2015-09-08 11:07
浏览 33
已采纳

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

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??

  • 写回答

2条回答 默认 最新

  • donglei1699 2015-09-08 11:08
    关注

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

    $result1 = $value[0];    
    $result2 = $value[1]; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog