php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21582 foreach/if/else strange problems
Submitted: 2003-01-11 11:39 UTC Modified: 2003-01-11 12:01 UTC
From: sazonenkov at yandex dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.0 OS: winXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sazonenkov at yandex dot ru
New email:
PHP Version: OS:

 

 [2003-01-11 11:39 UTC] sazonenkov at yandex dot ru
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);

?> 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-11 12:00 UTC] sazonenkov at yandex dot ru
sorry, not a bug - array index duplicate :(
 [2003-01-11 12:01 UTC] derick@php.net
bogus then
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 20:01:31 2024 UTC