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条)

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作