Quantcast

A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

annas

  • 2 years ago

New tutorial on PHP contents: 1.Logical operators. 2.while loop 3.foreach loop

  • This Question is Closed
  1. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    LOGICAL OPERATORS: Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value. However, the && and || operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value. TYPES OF LOGICAL OPERATORS: $a and $b And TRUE if both $a and $b are TRUE. $a or $b Or TRUE if either $a or $b is TRUE. $a xor $b Xor TRUE if either $a or $b is TRUE, but not both. ! $a Not TRUE if $a is not TRUE. $a && $b And TRUE if both $a and $b are TRUE. $a || $b Or TRUE if either $a or $b is TRUE.

  2. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    lets see examples: <?php // -------------------- // foo() will never get called as those operators are short-circuit $a = (false && foo()); $b = (true || foo()); $c = (false and foo()); $d = (true or foo()); // -------------------- // "||" has a greater precedence than "or" // The result of the expression (false || true) is assigned to $e // Acts like: ($e = (false || true)) $e = false || true; // The constant false is assigned to $f and then true is ignored // Acts like: (($f = false) or true) $f = false or true; var_dump($e, $f); // -------------------- // "&&" has a greater precedence than "and" // The result of the expression (true && false) is assigned to $g // Acts like: ($g = (true && false)) $g = true && false; // The constant true is assigned to $h and then false is ignored // Acts like: (($h = true) and false) $h = true and false; var_dump($g, $h); ?>

  3. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    WHILE LOOP: while loops are the simplest type of loop in PHP. They behave just like their C counterparts. The basic form of a while statement is: while (expr) statement The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time PHP runs the statements in the loop is one iteration). Sometimes, if the while expression evaluates to FALSE from the very beginning, the nested statement(s) won't even be run once. Like with the if statement, you can group multiple statements within the same while loop by surrounding a group of statements with curly braces, or by using the alternate syntax: while (expr): statement ... endwhile;

  4. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    Lets see an example: <?php /* example 1 */ $i = 1; while ($i <= 10) { echo $i++; /* the printed value would be $i before the increment (post-increment) */ } /* example 2 */ $i = 1; while ($i <= 10): echo $i; $i++; endwhile; ?> the working of while loop can be seen in the above example.

  5. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    FOREACH LOOP: The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. There are two syntaxes: 1.foreach (array_expression as $value) statement 2.foreach (array_expression as $key => $value) statement The first form loops over the array given by array_expression. On each iteration, the value of the current element is assigned to $value and the internal array pointer is advanced by one (so on the next iteration, you'll be looking at the next element). The second form will additionally assign the current element's key to the $key variable on each iteration. Lets see an example:

  6. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    Example 1: <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } // $arr is now array(2, 4, 6, 8) unset($value); // break the reference with the last element ?> Example 2: <?php foreach (array(1, 2, 3, 4) as &$value) { $value = $value * 2; } ?> NOTE: Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset().

  7. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    So thats it for this tutorial. Do comment on the tutorial.

  8. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    for those who join the tutorial now can also see the previous tutorials. 1. http://openstudy.com/study#/updates/4ffa87a8e4b058f8b7666f25 2. http://openstudy.com/study#/updates/4ffb14c9e4b058f8b766d273 3. http://openstudy.com/study?login#/updates/4ffd6086e4b00c7a70c5ed33

  9. sami-21
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    good one !

  10. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    @Muskan , @mathslover , @MathSofiya @mathhasproblems

  11. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    thank you @sami-21

  12. nilankshi
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    nice..

  13. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    @lalaly , @ash2326 , @moha_10 , @malihe

  14. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    @nilankshi thank you

  15. Muskan
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    v nys....gr8 @annas

  16. nilankshi
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    your welcome..@annas

  17. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    @Muskan thanks

  18. Hashir
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    great :D

  19. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    @Hashir thank you

  20. Muskan
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ur wlc

  21. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    @apoorvk , @Callisto

  22. ParthKohli
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Logical Operators https://developer.mozilla.org/en/JavaScript/Reference/Operators/Logical_Operators While loop: http://php.net/manual/en/control-structures.while.php Foreach loop: http://php.net/manual/en/control-structures.foreach.php Good luck doing it on your own next time.

  23. mathslover
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Wooh ! great tutorial annas. ... I think you are the master here of comp. science .. . thanks agan annas

  24. ParthKohli
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @mathslover Just look at the reply above yours.

  25. mathslover
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You mean that this is not personal tutorial ?

  26. ParthKohli
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No, it is not; and it hasn't cited the sources. Therefore, this can be called plagiarism. You have the evidence. "plagiarism (noun) The practice of taking someone else's work or ideas and passing them off as one's own." As defined by Dictionary.com

  27. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    my dear friend parth pointing finger at someone is quite easy... but practically doing something is different i can create a whole new website using php. between i took help from open source php manuals it not so called plagiarism ... so next time try to be more help than that . thank you for your feed back

  28. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    These are sentences taken to explain topics... i have a question the professor who taught us these subject they also take help from internet are they doing plagiarism too ??? i think not ... because things whose purpose is explain no matter what they are or where they are taken from comes under the category of helping .

  29. mathslover
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    gr8 points @annas ..

  30. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    thanks @mathslover

  31. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    and one more thing i m just a source to bring stuff to help that has been developed many years ago

  32. farmdawgnation
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @annas I'm afraid Parth has a point. Although you wrote your examples on your own, you did take content from MDN and the PHP manual verbatim without citation, and that's plagiarism. I'm going to let Colm decide how he wants to handle this (either by deleting the question, etc, etc) - but you definitely should not do that again without providing links to the sources in YOUR posts.

  33. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    ok @farmdawgnation

  34. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    @cshalvey just want to say one thing php manuals are open source so if i took help to explain some concepts then whats wrong with it alot of people here do such stuff why i m being pointed ?

  35. cshalvey
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    @Annas - Others *have* been warned about this kind of behavior. The issue here is not that you used the material - as you said, it's open-source so that's fine. The issue is *crediting* the source of this material. Otherwise, it does qualify as plagiarism as it appears you are passing off other people's work as your own. Please remember this in the future, as plagiarism is a very important issue to be aware of - ESPECIALLY now when every source of information is easily available on the internet. Thank you.

  36. moha_10
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    wow awesome annas good job

  37. annas
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 13

    Ok @cshalvey i'll be careful next time.

  38. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.