Jump to content

New to PHP and just trying to understand a little code.


JustTooCool

Recommended Posts

I hope I'm not annoying anyone or breaking the rules but I was wondering about this bit of code right here:

        " <?php

$people = Array(

Array('name' => 'Kalle', 'salt' => 856412),

Array('name' => 'Pierre', 'salt' => 215863)

);

for($i = 0; $i < sizeof($people); ++$i)

{

$people[$i]['salt'] = rand(000000, 999999);

}

?> "

 

Okay from what I can get from this $i will continue to increase and the code will execute until ..... this seems too random or me to realize the goal of this code.

<?php
// Populate $people with two arrays, each containing two entries.
// "name" and "salt"
$people = Array
          (
                Array('name' => 'Kalle', 'salt' => 856412),
                Array('name' => 'Pierre', 'salt' => 215863
          )
);

// for($i = 0; $i < the size of $people, which is two; add one to i)
for($i = 0; $i < sizeof($people); ++$i)
{
    // Assign a new value for "salt" on this array item.
    $people[$i]['salt'] = rand(000000, 999999);
}

?>

That cleared things up thanks a lot guys. PHP is a lot of fun. I started off on HTML but it was good and simple but for some reason I thought something was missing. Now that I have moved on to PHP I realized that it was control that creates all the fun. Hope to talk to you guys soon.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.