From:             [EMAIL PROTECTED]
Operating system: winXP
PHP version:      4.3.0
PHP Bug Type:     *General Issues
Bug description:  foreach/if/else strange problems

I have an array. Filter him in foreach cycle. Size of array is 8. Have a
condition if/else - not all part of array come throw

code:

<?php
        $info =
unserialize('a:8:{i:100;a:5:{s:2:"id";s:1:"1";s:7:"sponsor";s:1:"1";s:6:"weight";s:3:"100";s:3:"url";s:9:"ahsfd.com";s:4:"html";s:4:"html";}i:200;a:5:{s:2:"id";s:1:"2";s:7:"sponsor";s:1:"1";s:6:"weight";s:3:"200";s:3:"url";s:12:"kilemall.net";s:4:"html";s:4:"html";}i:300;a:5:{s:2:"id";s:1:"3";s:7:"sponsor";s:1:"1";s:6:"weight";s:3:"300";s:3:"url";s:10:"fuck2k.com";s:4:"html";s:4:"html";}i:400;a:5:{s:2:"id";s:1:"4";s:7:"sponsor";s:1:"2";s:6:"weight";s:3:"400";s:3:"url";s:7:"mail.md";s:4:"html";s:4:"html";}i:500;a:5:{s:2:"id";s:1:"5";s:7:"sponsor";s:1:"4";s:6:"weight";s:3:"500";s:3:"url";s:10:"quake3.com";s:4:"html";s:4:"html";}i:600;a:5:{s:2:"id";s:1:"6";s:7:"sponsor";s:1:"4";s:6:"weight";s:3:"600";s:3:"url";s:6:"sex.md";s:4:"html";s:4:"html";}i:700;a:5:{s:2:"id";s:1:"7";s:7:"sponsor";s:1:"5";s:6:"weight";s:3:"700";s:3:"url";s:6:"sex.ru";s:4:"html";s:4:"html";}i:800;a:5:{s:2:"id";s:1:"8";s:7:"sponsor";s:1:"6";s:6:"weight";s:3:"800";s:3:"url";s:7:"sex.net";s:4:"html";s:4:"html";}}');


        $cookie = '1|3|5|7|9|11|13|15|17|19|21';
        $cookie_br = explode('|', $cookie);
        $spid = '';

        $info2 = array();
        $info_rest = array();
        $i=0;
        $i_rest=0; 
        echo "<hr>info <font color=red>".count($info)."</font>";
        print_r($info);
        foreach  ($info as $k=> $line) 
        {
                mt_srand((float)microtime()*1000000);// untill php4.2.0
                $weight = mt_rand(1,10)* $line['weight']; // rand 
                if (!in_array($line['id'], $cookie_br) || ($spid==$line['sponsor']))
                {
                        $info2[$weight] = array('id'     =>$line['id'],
                                                    'sponsor'=>$line['sponsor'],
                                                    'weight' =>$weight,
                                                    'url'    =>$line['url'],
                                                    'html'   =>$line['html']);
                        $i++;//counter 
                }
                else//rest
                {
                        $info_rest[$weight] = array('id' =>$line['id'],
                                                    'sponsor'=>$line['sponsor'],
                                                    'weight' =>$weight,
                                                    'url'    =>$line['url'],
                                                    'html'   =>$line['html']);
                        $i_rest++;//counter
                }
        }
        echo "<hr>info2 <font color=red>".count($info2)."</font>";
        print_r($info2);
        echo "<hr>inforest <font color=red>".count($info_rest)."</font> i_rest
".$i_rest;
        print_r($info_rest);

?> 
-- 
Edit bug report at http://bugs.php.net/?id=21582&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=21582&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=21582&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=21582&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=21582&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=21582&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=21582&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=21582&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=21582&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=21582&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=21582&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21582&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=21582&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=21582&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=21582&r=gnused

Reply via email to