Bifalgorithm post · Computer science one · Useful Functions

How can you print the contents of a PHP array in a readable format?

How can you print the contents of a PHP array in a readable format? (Computer science one · Useful Functions) — "For convenience and debugging, a special funct…

Ideas in this flowchart

  • The print_r() function displays array contents for convenience and debugging.
  • print_r() prints the contents of an array.
  • The output is formatted in a human-readable way.
  • The format resembles key-value array initialization syntax.
  • Example array: foo maps to 5, 4 maps to bar, 0 maps to 3.14, and baz maps to ten.
  • The array is passed to print_r($arr).
  • The resulting output is labeled Array and enclosed in parentheses.
  • Each array entry is displayed with its key in brackets and its corresponding value.
Feed/

How can you print the contents of a PHP array in a readable format?

No cover

Channel

Computer science one

1 page

"For convenience and debugging, a special function, print_r() allows you to print the contents of an array in a human-readable format that resembles the key-value initialization syntax above. For example,\n\n$arr = array(\n\n\"foo\" => 5,\n\n4 => \"bar\",\n\n0 => 3.14,\n\n\"baz\" => \"ten\"\n\n);\n\nprint_r($arr);\n\nwould end up printing\n\nArray\n\n(\n\n[foo] => 5\n\n[4] => bar\n\n[0] => 3.14\n\n[baz] => ten\n\n)"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.