Jump to content

Merkaber

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by Merkaber

  1. Thank you for your reply,

    I understand the if clause, but I don't understand, why we need this if clause. There is no way, that $hint is not empty. $hint is for all times empty, thats what I understand. Because we declare it empty at the top and there is no other input for $hint.

  2. Hello everyone,

     

    I have a question about the PHP - AJAX example (http://www.w3schools.com/php/php_ajax_php.asp).

    In the PHP file, there is the variable " $hint ". But what is this variable used for?

    Here the code:

    $q = $_REQUEST["q"];$hint = "";// lookup all hints from array if $q is different from ""if ($q !== "") {    $q = strtolower($q);    $len=strlen($q);    foreach($a as $name) {        if (stristr($q, substr($name, 0, $len))) {            if ($hint === "") {                $hint = $name;            } else {                $hint .= ", $name";            }        }    }}

    You are declaring $hint = "". After there is no input, that could happen to $hint. Why there is the if clause?

    Maybe I am blind, but I don't get it.

     

    Second questions is about this code part:

    echo $hint === "" ? "no suggestion" : $hint;

    How you can use operators without function, what does ' $hint === "" ' and what does ' : ' ?I already red the whole example more than twice... but I don't get it.

    A short explanation or a link to another website which is explaining these would be awesome. Thank you in advance!

     

    (By copy and pasting, the example works, but I wanna understand it)(I am not native English speaker, please excuse my mistakes)

×
×
  • Create New...