php未定义数组索引,php中数组未定义的索引错误(注意)

你想过用foreach循环替换for循环吗?

如:

foreach( $tests as $i => $test )

这样做的好处是在$test[$i]中有一个值。然后,在你的

$test[ $i ][ $j ] == null

阻止,放置此:

if ($j != $k &&

// I suspect that this will cause errors too.

// Do yourself a favor and add this sanity check.

isset( $test[$j] ) && $test[$j] != null &&

isset( $test[$k] ) && $test[$k] != null) {

$currentK = $test[$k];

$currentJ = $test[$j];

// Use debug lines if setting things directly won't work

if( !isset( $coin[ $currentJ ] ) || !is_array( $coin[ $currentJ ] ) )

{

// $coin[ $currentJ ] = array();

die( "

$currentK $currentJ \n" .  print_r( $coin ) );

}

$currentCoin =& $coin[ $currentJ ];

if( !isset( $currentCoin [ $currentK ] ) ||

!is_array( $currentCoin [ $currentK ] ) )

{

// Just curious, but when doing these checks before,

// did you remember to assign a numeric value here?

//

// $currentCoin[ $currentK ] = 0;

die( "

$currentK $currentJ \n" .  print_r( $coin ) );

}

$currentCoin[ $currentK ] += 1 / ($some_var - 1);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值