dqnrk44682 2012-10-19 17:29
浏览 24

PHP数组未设置问题

I'm looking for a solution to unset array keys. How can I get this working without any php notice?

Thanks

Notice: Undefined offset: 2099 in test1.php on line 102

$words = array('one','two','three','four','five','six','seven','0987');


foreach ($words as $key => $value){
    if (preg_match('/[0-9]{4,7}/',$value)){
    unset($words[$key]);
    }
}

$array_a = array(
array('surname'=>'a'),
array('surname'=>'b'),
array('surname'=>'c')
);

$array_b = $words ;


for ($i = 0; $i < count($array_b); $i++){
    if ( count( $array_a[$i % count($array_a)] ) = 1 ){ 
        echo '<pre>';
        echo $array_a[$i % count($array_a)]['surname'] . '    ' . $array_b[$i];
        echo '</pre>';
    }
}
  • 写回答

1条回答 默认 最新

  • dongsiju1941 2012-10-19 17:49
    关注

    Interesting! You need to use native function isset(). Try something like this:

    $key = $i % count($array_a);
    if(isset($array_a[$key]) && is_array($array_b)){
        for ($i = 0; $i < count($array_b); $i++){
            isset($array_a[$key]['post']){
                  echo '<pre>';
                  echo $array_a[$key]['post'];
                  echo '</pre>';
            } else {
                 echo 'Some message error!';
            }
        }
    
    } else {
        echo 'Some message error!';
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿