Page 1 of 1

Mysterious Code

Posted: Thu Jul 17, 2008 9:35 pm
by biokr78
Hey, I'm trying to figure out how

$arrMD5Chars="a4cd31g";
foreach ($arrMD5Chars as $value) //for each value in arrMD5Chars, given the value $value
{
$intTotal += '0x0'.$value;
}

creates the value $intTotal. Specifically, what does the "'0x0'.$value" mean?

Re: Mysterious Code

Posted: Thu Jul 17, 2008 9:46 pm
by Benjamin
It doesn't. foreach() doesn't iterate through strings.

http://us2.php.net/manual/en/control-st ... oreach.php

Re: Mysterious Code

Posted: Fri Jul 18, 2008 1:48 am
by Luke
You could turn it into an array if you really wanted to...

Code: Select all

$arrMD5Chars=str_split("a4cd31g");
foreach ($arrMD5Chars as $value)  {
    $intTotal += '0x0'.$value;
}

Re: Mysterious Code

Posted: Fri Jul 18, 2008 9:38 am
by biokr78
Okay, so $arrMD5Chars is an array that contains characters like ['a', 'b', '3', 'z', etc...]. $intTotal starts of equal to zero. What would the line "$intTotal += '0x0'.$value;" accomplish?