Jump to content
Larry Ullman's Book Forums

jimlongo

Members
  • Posts

    3
  • Joined

  • Last visited

jimlongo's Achievements

Newbie

Newbie (1/14)

  • Week One Done Rare
  • One Month Later Rare
  • One Year In Rare

Recent Badges

1

Reputation

  1. pear was installed on my version of MAMP 2.1.3 / php5.4.10 on OSX 10.7.5 The main thing was to make sure that the pear binaries were in the path, and that in 10.7.5 seems to be in set in /etc/paths add the line at the end of that file '/Applications/MAMP/bin/php/php5.4.10/bin also found some helpful instructions on this page
  2. Thanks HartleySan. When you say php.net has a decent description are you referring to the following . . . The construct switch(true) is a little beyond the single Chapter 6 description we've been introduced to so far. Back to the question of syntax, does it make more sense to compare strings than numbers with switch? I feel like I've descended down a rabbit hole, but I'm sure it will all make sense eventually, for instance (and I guess this is confirming what you wrote) <?php $i=0; switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; } ?> returns "i equals 0" . . . however <?php $i=0; switch ($i) { case $i==0: echo "i equals 0"; break; case $i==1: echo "i equals 1"; break; } ?> returns "i equals 1"
  3. Hi, I'm struggling with this particular use of a switch statement. I'm trying to use a case that is a range of numbers. Seems to work alright, until you change the variable $number to 0 (ZERO). <?php $number=3; switch ($number) { case $number >=0 && $number <=10: print "The number is between 0 and 10"; break; case $number >=11 && $number <=20: print "The number is between 11 and 20"; break; default: print "Your number is not between 0 and 20"; } ?> Or many other forms I've tried. case >=0 && <=10: case ">=0 && <=10": case ">=0" && "<=10": case ($number >=0 && $number <=10): case ($number >="0" && $number <="10"): I guess the longer question is what is the correct way to write this idea so that it works? I've looked at it so long I'm probably missing something real simple (like how to deal with zero as an integer), but I can't see it and any help would be appreciated greatly. Many Thanks, love the book!
×
×
  • Create New...