What is the PHP equivalent of Java System.out.println

Viewed 848

What is the equivalent print syntax this Java code in PHP?

System.out.println("Hello World");
System.out.println("Lorem Ipsum");

I can achieve this in PHP by using "\n" in the end of the string

print "Hello World\n";
print "Lorem Ipsum";

But I don't want to use "\n" every time I want to print something on console

1 Answers

I'm sure that you've worked it out by now that you need a function to do this (from the very useful comments). But in case others are looking for something quick and simple:

<?php

function println(string $string = '')
{
    print($string . PHP_EOL);
}

Make your own improvements if needed, but this should work.

Related