How to: println in PHP
Outputting to your shell or terminal to inform the user of the outcome of a program or valuable debugging information is an essential of every programming language.
Rust
In rust we can use the println!
macro to write to output strings and variables.
fn main() {
println!("Hello World!");
println!("My name is {}", "Jonathan");
println!("NOT true is {}", !true);
}
If we want to log the shape of a struct with its values we need to use a different placeholder in our log statement:
#![allow(unused)]
fn main() {
#[derive(Debug)]
struct Point {
x: i32,
y: i32,
}
let origin = Point { x: 5, y: 13 };
println!("point debug: {origin:#?}")
}
More println References
PHP
In PHP you can print to the terminal or the log by using var_dump
:
<?php
$a = array(1, 2, array("a", "b", "c"));
var_dump($a);
?>