Imprimir valors

Tenim dues formes molt semblants de mostrar valors per pantalla echo i print

La diferència és que echo no retorna cap valor i print retorna 1.

echo

Es pot utilitzar sense o amb parèntesis: echo o echo().

echo "<h2>PHP is Fun!</h2>";

Fixeu-vos que el text pot tenir etiquetes HTML.

<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;

echo "<h2>" . $txt1 . "</h2>";
echo "Study PHP at " . $txt2 . "<br>";
echo $x + $y;
?>

Provar l'exemple

IMPORTANT: Fixeu-vos en què per encadenar text (entre cometes) i les variables utilitzem el punt .

print

Es pot utilitzar sense o amb parèntesis: print o print().

print "<h2>PHP is Fun!</h2>";

#FpInfor #DawMp07Uf01 #DawMp07Uf02 #DawMp07Uf03 #PHP

#FpInfor #AsixMp09Uf01 #PHP

Autor: Sergi Coll

Modificat: 18/12/2018

results matching ""

    No results matching ""