Jump to content

steadythecourse

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

steadythecourse's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. BlueSkyIS, Thanks! great explanation, and extremely stupid on my part. again Thanks! steadythecourse
  2. Hi! This bit of code does exactly what I want it to just not sure why. The way I would (***_u_me) this code to be written would be to replace the echo ($array_2[$index]); with echo ($array_2[$value]); to get the output I'm getting. Basically the foreach loop loops through $array_1 when it finds a key with a null value it outputs the $value or the $index which ever I decide to output of $array_2 which corresponds to that value. when I echo ($array_2[$value]) I get no output and when I echo ($array_2[$index]) I get the wanted output below. It doesn't seem right <?php function test() { $array_1 = array("Matt" => NULL, "Kim" => 1, "Jessica" => NULL, "Keri" => 1); $array_2 = array("Matt","Kim","Jessica","Keri"); foreach ($array_2 as $index => $value) { if (!isset($array_1[$value])) { echo ($array_2[$index]); echo "<br />"; } } } test(); ?> output Matt Jessica Thanks, steadythecourse
  3. HI! Can someone explain the variables $value and $key that are being produced at the end of the output by the following code. It seems like the foreach loop is creating two extra variables. <?php $test_1 = "matt"; $test_2 = "kim"; $test_3 = "jessica"; $test_4 = "keri"; foreach ($GLOBALS as $key => $value) { echo $key . "- - -" . $value; echo "<br />"; } ?> Output GLOBALS- - -Array _POST- - -Array _GET- - -Array _COOKIE- - -Array _FILES- - -Array test_1- - -matt test_2- - -kim test_3- - -jessica test_4- - -keri value- - -keri key- - -value Thanks! steadythecourse
  4. Hello All! Can anyone explain why when I run the following code <?php print_r($GLOBALS); ?> I get the following output Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) ) which is expected since register_globals is set to off and no variables are defined, but when I add the following code. which is just to echo out a variable from the superglobal $_SERVER, the print_r($GLOBALS) now outputs all the superglobal $_SERVER variables as if echo somehow made all the variables available to the script and now $GLOBALS sees them. maybe a stupid question I don't know. For obvious reasons I can't show the output, but it's easy enough to run the code to view your systems output. <?php print_r($GLOBALS); echo "<br />"; echo "<br />"; echo $_SERVER["DOCUMENT_ROOT"]; ?> Thanks, steadythecourse
  5. thanks mjdamato, I got it! steadythecourse
  6. Hi All, I'm trying to understand the logic behind this bit of code I found. I (think I) get that it takes an argument which in this case is a number, an checks to see if the array isset, then uses a while loop to loop through the possible values taking each value and placing it into another function which performs some task. What I'm really confused about is how the code is using unset, If I'm correct it's unsetting the incremented value which is the value that should be used in the next iteration, now I know this is not the case, but I don't understand why this is working. I have included the code in the topic and I also wrote a small piece of code to mirror this so I could play around with it in hopes of understanding the logic but it gives me a syntax error in my IDE when I try to unset the incremented value. I know this is probably something really stupid so be kind. <?phpdefine("NUM_0", 0);define("NUM_1", 1);define("NUM_2", 2);define("NUM_3", 3);define("NUM_4", 4);function function_1($position) { static $positions = array(NUM_0,NUM_1,NUM_2,NUM_3,NUM_4,), $index = 0; if (isset($positions[$index])) { while ($position >= $index) { $current_position = $positions[$index]; unset($positions[$index++]); function_2($current_position); } }}function function_2($position) { switch ($position) { case 0: echo '$position equals 0 <br />'; break; case 1: echo '$position equals 1 <br />'; break; case 2: echo '$position equals 2 <br />'; break; case 3: echo '$position equals 3 <br />'; break; case 4: echo '$position equals 4 <br />'; break; }}function_1(NUM_4);[b][u]output![/u]$position equals 0$position equals 1$position equals 2$position equals 3$position equals 4 [/b]function test() { static $var_1; $var_1 = 10; if (isset($var_1)) { while ($var_1 >= 0) { $var_2 = $var_1; unset ($var_1++); // syntax error on this line. echo $var_2; } }}test();?>
×
×
  • 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.