Jump to content

Muck A. Round

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by Muck A. Round

  1. There are some fundamental things here about how and when values get passed that I need to do more of in exercises to commit to understanding and memory.
  2. Ah - I didn't make all the changes - putting $value in the static function and if/else. I had only added $x to the call. Thanks !!
  3. Ah Thank you !! Wait... that still doesn't work. I have to declare $x as global or something.
  4. I am missing something with this code I decided to try. See comment in code for problem converting 0 or 1 to TRUE or FALSE ? <?php $x = 11; var_dump ($x & 1); echo "<br>"; // // var_dump is showing int(0) or int(1) for even or odd but function below is always saying even??? // class calculations { public static function OddorEven() { if ($x & 1) { echo "x is odd";} else { echo "x is even";} } } // Call static method calculations::OddorEven(); ?>
  5. Thanks 🙂 I'll put my suggestions there.
  6. It seems there are more examples later in this section where they have a "Try it yourself" but the code doesn't produce anything in the output. It would be clearer if they either modified the code to produce at least something, or explain that the code won't produce any output because xyz.
  7. Yes - that's the code copy/pasted from the "Try it yourself". So they could have explained nothing would happen (or even not bother making it a "Try it yourself" when trying it doesn't do anything except show you the code again?). Looking at subsequent examples, I see that more code is necessary. It's good to know what these layers of code do, but was a little confusing when you hit the button and nothing happens.
  8. When I "Try it yourself" on the first example, and hit RUN, nothing appears in the right box. Is this correct? If so, I'm not sure of the point. Below is the code for that example. <!DOCTYPE html> <html> <body> <?php class Fruit { // Properties public $name; public $color; // Methods function set_name($name) { $this->name = $name; } function get_name() { return $this->name; } } ?> </body> </html>
  9. Ah - thanks everyone. What I was missing was that an associative array is defined as KEY => VALUE. So when you say "value" you're not talking about the value (or amount?) of any given entry, but value as the entity that each key is associated with.
  10. I feel like I'm missing something on the example for Sort Array (Ascending Order), According to Value - asort(). I added a var_dump and also switched the variables to ABC, and don't see that any sorting is occurring. <!DOCTYPE html> <html> <body> <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); asort($age); var_dump($age); echo "<br><br>"; foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } echo "<br>"; $age = array("C"=>"35", "B"=>"37", "A"=>"43"); asort($age); var_dump($age); echo "<br>"; echo "<br>"; foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } ?> </body> </html>
×
×
  • Create New...