PHP Tweaks :)

echo
  • Outputs one or more strings separated by commas
  • No return value
    e.g. echo "String 1", "String 2"
print
  • Outputs only a single string
  • Returns 1, so it can be used in an expression
    e.g. print "Hello"
    or, if ($expr && print "foo")
print_r()
  • Outputs a human-readable representation of any one value
  • Accepts not just strings but other types including arrays and objects, formatting them to be readable
  • Useful when debugging
  • May return its output as a return value (instead of echoing) if the second optional argument is given
var_dump()
  • Outputs a human-readable representation of one or more values separated by commas
  • Accepts not just strings but other types including arrays and objects, formatting them to be readable
  • Uses a different output format to print_r(), for example it also prints the type of values
  • Useful when debugging
  • No return value

0 comments: