[thelist] PHP Array loop help

Crous, Michelle Mcrous at thurrock.gov.uk
Mon May 13 04:31:01 CDT 2002


CDitty wrote:
> Anyone have any ideas on this? I'm clueless.
>
> Chris

Chris,

It's a bit rough and ready but using a links.db file containing this:

43|data1|data2|data3;
50|data1|data2|data3;
77|data1|data2|data3;
84|data1|data2|data3;

and the following code:

<?php
if(!IsSet($HTTP_COOKIE_VARS["test"])){
	setcookie("test", "43|50|77|84|", time()+31536000);  // expire in 1
year
}
$myCookie = explode("|", $HTTP_COOKIE_VARS["test"]);
foreach ($myCookie as $v){
	$links_database = "/data/links.db";
	$fd = fopen($links_database, "r");
	$contents = fread($fd, filesize($links_database));

	$cookieInfo = explode(';', $contents);
	foreach ($cookieInfo as $info) {
		$value = explode('|', $info);
		if($v == $value[0]){ // Must match value.
			foreach ($value as $result) {
				print "Link Info: $result\n<br />";
			}
		}

	}
	fclose($fd);
}
?>

I got this output:

Link Info: 43
Link Info: data1
Link Info: data2
Link Info: data3
Link Info: 50
Link Info: data1
Link Info: data2
Link Info: data3
Link Info: 77
Link Info: data1
Link Info: data2
Link Info: data3
Link Info: 84
Link Info: data1
Link Info: data2
Link Info: data3

Hope this helps,

twigletmac


The information in this e-Mail and any attachment(s) are intended to be
confidential and may be legally privileged. Access to and use of its
content by anyone else other than the addressee(s) may be unlawful and
will not be recognised by Thurrock Council for business purposes. Thurrock
Council cannot accept any responsibility for the accuracy or completeness
of this message as it has been transmitted over a public network.

Any opinions expressed in this document are those of the author and do
not necessarily reflect the opinions of Thurrock Council.

Any attachment(s) to this message has been checked for viruses, but please
rely on your own virus checker and procedures.

If you contact us by e-mail, we will store your name and address to
facilitate communications.
____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Control Centre. For further information visit
http://www.messagelabs.com/stats.asp



More information about the thelist mailing list