Jump to content

W3schools Php Tutorial "php Filter" Section


Bennie3

Recommended Posts

Hi, everyone! I just been accepted into this W3Schools Forum. I've been studying various tutorials on the W3Schools website for about 3/4 of a year now. Currently, I'm studying the PHP tutorial. I'm confused by the direction of the arrows of the "max_range" options in the PHP Filter examples in the "Advanced" and "Reference" sections of the tutorial. They seem to all be pointing in the wrong direction.Here's an example of what I mean, from the PHP Filter "Options and Flags" subsection:<?php$var=300;$int_options = array("options"=>array ( "min_range"=>0, "max_range"=>256 ));if(!filter_var($var, FILTER_VALIDATE_INT, $int_options)) { echo("Integer is not valid"); }else { echo("Integer is valid"); }?>[My question is: If the integer range in this example is supposed to be between 0 and 256, shouldn't the "max_range" option be written: "max_range"=<256 ?] I apologize if I'm missing something obvious; I'm sure I'll figure this all out eventually.Thank you for any feedback you can offer,Bennie3

Link to comment
Share on other sites

Hi, everyone! I just been accepted into this W3Schools Forum. I've been studying various tutorials on the W3Schools website for about 3/4 of a year now. Currently, I'm studying the PHP tutorial. I'm confused by the direction of the arrows of the "max_range" options in the PHP Filter examples in the "Advanced" and "Reference" sections of the tutorial. They seem to all be pointing in the wrong direction.Here's an example of what I mean, from the PHP Filter "Options and Flags" subsection:<?php$var=300;$int_options = array("options"=>array ( "min_range"=>0, "max_range"=>256 ));if(!filter_var($var, FILTER_VALIDATE_INT, $int_options)) { echo("Integer is not valid"); }else { echo("Integer is valid"); }?>[My question is: If the integer range in this example is supposed to be between 0 and 256, shouldn't the "max_range" option be written: "max_range"=<256 ?] I apologize if I'm missing something obvious; I'm sure I'll figure this all out eventually.Thank you for any feedback you can offer,Bennie3
=> doesn't mean "greater or equal", it just means that you're assigning the value to the "max_range" element of the array. Here's how an array is made in PHP:
$A = array("element1"=> "value","element2"=> "value","element3"=> "value","element4"=> "value")

In the filter, you're just giving the function an array where "min_range" is 0 and "max_range" is 256.

Link to comment
Share on other sites

Dear Ingolme,Thank you very much for your explanation. After reading it, I went over to the "PHP Arrays" section, where I noticed that same "operator," I guess it's called, used in an example for "Associative Arrays":[$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);].But, I didn't notice any explanation for the symbol, nor did I see one in the "PHP Operator" section, other than it's other meaning of "more than or equal to."So, my next question is: Is that symbol specifically mentioned somewhere in the W3Schools PHP or SQL Tutorials--whichI understand are merely summaries of the two topics--or, will I find the symbol listed in a more detailed book on PHP and MySQl, that I'll be getting after I finish the tutorials?Thanks again for your indulgence.Con mucho gusto,Bennie3

Link to comment
Share on other sites

The proper name for the ≥ operator is the "greater than or equal to" operator. In PHP that is written using the "greater than" operator > followed by the "equal to" operator, as such: >=. However, the associative array key-value delimiter is written as such: =>, which if taken as a logical operator reads "equal to or greater than", which is not the same as "greater than or equal to", and therefore not valid. :)

Link to comment
Share on other sites

Hey, Ingolme and Synook! Thanks for your input.Just for the heck of it, after reading your posts, I typed in "PHP Tutorials" into my computer's search gizmo. From a list it displayed, I randomly clicked on a link to a PHP article on sitepoint.com: http://www.sitepoint.com/subcat/php-tutorials. Once on that webpage, I typed "=> operator" into their own search gizmo at the top of the page I was on. I was connected to a listing of sitepoint Articles and Blog Posts. One of the Blog Posts was entitled "What do you call this: =>".That blog, at http://www.sitepoint.com/blogs/2005/09/27/...-you-call-this/, said,' "Reportedly it’s called the “double arrow”,' referring to "=>". If you click on the word "Reportedly" there, you're taken to a Google Groups, http://groups.google.com/group/comp.lang.p...8c125b22241cce2, where someone asks what "=>" means, and others give their opinions. If you click on the words “double arrow”, you'll be taken to http://us3.php.net/tokens, which is a "List of Parser Tokens" page. The listing "T_DOUBLE_ARROW => array syntax" provides a link, when you click on "array syntax," that takes you to an "Arrays" page, http://us2.php.net/manual/en/language.type...es.array.syntax, where they offer the following: SyntaxSpecifying with array()An array can be created by the array() language construct. It takes as parameters any number of comma-separated key => value pairs. "array( key => value , ... )// key may only be an integer or string// value may be any value of any type " ,but they don't give an actual description of what "=>" means.If I stumble upon anything more specific about this mysterious "double arrow" with only one arrow, I'll post it here. In the meantime, I'll be studying my W3Schools tutorials.G'Day Mates!Bennie3

Link to comment
Share on other sites

The => character sequence seperates the key and value in an associative array...For example:

$array = array("key1" => "value1", "key2" => "value2");echo $array['key1']; //echos "value1"echo $array['key2']; //echos "value2"

The "single arrow", as I suppose -> would be called if => is a "double arrow", is the property and method selector for objects.For example:

class Test {	 public $property;	 function method() {		  $this->property = "Test value";	 }}$test = new Test();$test->method();echo $test->property; //echos "Test value"

Link to comment
Share on other sites

It is curious the things that manuals take for granted. This seems like a simple thing, and to anyone who knows about arrays, the function of => will be intuitively obvious. Even if you've never seen it before, you'll be looking for something like it. But to a newcomer, all things need explanation.A similar example is =, the assignment operator. We've fielded questions on that and == before. The utility seems obvious. But if that were true, then there wouldn't be alternatives (in other languages) like "set", "let" or =: How easy for a manual to not explain it, or to banish the explanation to a far-off corner.20 years ago, when I first started to program seriously, I read a manual that kept referring to the escape character. Nowhere did it define the escape character. I kept hitting the escape key on my keyboard and getting frustrated that that wasn't it. When I finally found out, I was furious.Technical-writing editors put this acronym in the margins sometimes: COIK (Clear Only If Known). That sums up the problem, I think.

Link to comment
Share on other sites

Dear Synook,All the tutorials I've read, on W3Schools and elsewhere, explain what all the other "operators" and symbols mean; so you have to conclude that the original reason for "=>" to be used to "separate" a "key" and a "value," as opposed to using say, a "#*^@" compilation of keyboard characters as the separator, has been been long since lost in the shuffle, and no one really knows anymore. Like DD mentioned, intuition has to fill the gaps in cases like these.And speaking of the "Escape Key": for about a year and a half after getting my first computer, I was inadvertently hitting the "Insert Key" while typing E-mails, and would spend hours trying to figure out why my computer was eating up the words as I typed, until I inadvertently would hit the Insert Key again, correcting the problem!Bennie3

Link to comment
Share on other sites

so you have to conclude that the original reason for "=>" to be used to "separate" a "key" and a "value," as opposed to using say, a "#*^@" compilation of keyboard characters as the separator, has been been long since lost in the shuffle
Well, it looks like an arrow... like saying that the "key" points to the "value", "key" => "value". :)By the way you can't use => for logical comparison, e.g.:
if ($a => $b) //Error!

Anyway, don't worry, you haven't encountered the Paamayim Nekudotayim yet!

Link to comment
Share on other sites

technical_questions::comedic_interlude=>echo ('ha','ha')Thanks for the links, Synook. As you probably guessed, I was joking about your "::" reference.That's a pretty fancy symbol you've got spinning around there. Where do you get them?Bennie3

Link to comment
Share on other sites

I made it ages ago in Blender :)

Technical_questions::comedic_interlude->laugh = array("ha" => "ha");

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...