Home>

I don't understand the concept of as in foreach that appears in php.
What does as means when I translate it into Japanese?
I know how to use it, but it doesn't come out very well.
I would like to be able to properly verbalize and be able to give kind illustrations.
Thank you.

I'm looking up the dictionary.
I didn't really come to mean "as", so I asked a question.

php
  • Answer # 1

    Didn't you look up the dictionary? The most common meaning is "as".

    From Goo dictionary

    1. As (...);And (...)
    a tiger as a pet
    Tiger as a pet
    regard a person as a fool
    Treat people as stupid

  • Answer # 2

    I would like to be able to properly verbalize and be able to give kind illustrations.

    No need to do that. thisasHas been decided to "use that string",No room for change or developmentTherefore, it is correct to memorize it as "use this".

  • Answer # 3

    As a claim with Maisumakun, I suffer.

    The following two are contradictory.

    foreach as concept

    When you correct it to Japanese

    If you want to know the concept, you should understand "how the syntax works".
    It's strange that you should look up a dictionary like "If you fix it in Japanese".

    All you have to do is check the document as a specification and understand only the function.

    Therefore, it is best to tell them to read the document as it is, only the facts, the functions, and no interpretation or analogy is necessary. Strange analogies make it harder to understand and deviate from the essence.
    What kind of situations and how are they used? What kind of input is used to produce what kind of output?

    There are quite a few syntaxes and functions that are abbreviated or translated and that are far from the "actual English word or grammar" or that adopt minor meanings (though I do not know in detail).

    It is an example of substr or htmlspecialchars, but if you try to "correct it to Japanese", it is quite impossible.
    That's all HTML tags. Of course, there is something like "what does it stand for?", but even if you remember it, the use of programming is rarely useful.

    It is still understandable if you translate the functional description of the original text in English, but it is not a hindrance to learning if you think of the function itself as a "syntax".

    It is more important to "understand the role of the function and use it in the appropriate situations".

  • Answer # 4

    In case of foreach like below

    $array = [1,2,3,4,5];
    foreach($array as $value){
    }

    Loop through the elements of $array from the beginning and copy the element of the current week "as" $value
    It behaves like.
    If you understand this behaviorasIsn't there a sense of incongruity in interpreting as'='?'


    It's not limited to foreach, but it's quite unreasonable to capture keywords in syntax with words.
    (Because the control syntax does not have to be explained in the text, it is standardized so that it can be omitted except for the minimum required keywords.)

    After grasping the behavior first, it is not too late to think whether or not it will fit properly in the straightforward sense.
    Since many control syntaxes and symbols are not in English, it is recommended to learn the behavior directly rather than translating from English to Japanese.

  • Answer # 5

    The meaning of "as" is most comfortable.

    The following code doesn't mean much to use foeach,
    Can be understood as

    $arr = array(2,4,6,8);
      // Think of the value of the element of $arr as $value in this scope
    foreach($arr as $value) {
        echo $value .',';
    }
    //output
    //2,4,6,8,
    /*
    What I'm doing is roughly the same as this (not exactly)
    for($i=0;$i<count($arr);$i++){echo $arr[$i] .",";
    }
    */
    $arr = array(2,4,6,8);
      // Think of the element of $arr as $key and the element value as $value in this scope
    foreach($arr as $key =>$value){
        echo'arr[' .$key .'] =>'. $value. "\n";
    }
    //output
    //arr[0] =>2
    //arr[1] =>4
    //arr[2] =>6
    //arr[3] =>8
    /*
    What I'm doing is roughly the same as this (not exactly)
    for($key=0;$key<count($arr);$key++){
      echo'arr[' .$key .'] =>'. $arr[$key] ."\n";
    }
    */

    Each time it is repeated in foreach, it references the next element, the next element,
    The value of the referenced element is assigned to the variable specified by "as variable name".

    If it is $arr as $value, process the value of the element of $arr as $value,
    It means that it can be handled with $value in the scope of foreach.

    I think that the word "as" will be most appropriate from the mechanism, but will it be transmitted?

Related articles