Mysterious Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
biokr78
Forum Newbie
Posts: 2
Joined: Thu Jul 17, 2008 9:33 pm

Mysterious Code

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Mysterious Code

Post by Benjamin »

It doesn't. foreach() doesn't iterate through strings.

http://us2.php.net/manual/en/control-st ... oreach.php
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Mysterious Code

Post 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;
}
biokr78
Forum Newbie
Posts: 2
Joined: Thu Jul 17, 2008 9:33 pm

Re: Mysterious Code

Post 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?
Post Reply