<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.print.php',
    1 => 'print',
    2 => 'Output a string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Функції',
  ),
  'prev' => 
  array (
    0 => 'function.parse-str.php',
    1 => 'parse_str',
  ),
  'next' => 
  array (
    0 => 'function.printf.php',
    1 => 'printf',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/print.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.print" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">print</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">print</span> &mdash; <span class="dc-title">Output a string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.print-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>print</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$expression</code></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   Outputs <code class="parameter">expression</code>.
  </p>
  <p class="para">
   <code class="literal">print</code> is not a function but a language construct.
   Its argument is the expression following the <code class="literal">print</code> keyword,
   and is not delimited by parentheses.
  </p>
  <p class="para">
   The major differences to <span class="function"><a href="function.echo.php" class="function">echo</a></span> are that
   <code class="literal">print</code> only accepts a single argument and always returns
   <code class="literal">1</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.print-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">expression</code></dt>
     <dd>
      <p class="para">
       The expression to be output. Non-string values will be coerced to strings,
       even when <a href="language.types.declarations.php#language.types.declarations.strict" class="link">the
       <code class="literal">strict_types</code> directive</a> is enabled.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.print-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns <code class="literal">1</code>, always.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.print-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <code class="literal">print</code> examples</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"print does not require parentheses."</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// No newline or space is added; the below outputs "helloworld" all on one line<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"world"</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"This string spans<br />multiple lines. The newlines will be<br />output as well"</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"This string spans\nmultiple lines. The newlines will be\noutput as well."</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// The argument can be any expression which produces a string<br /></span><span style="color: #0000BB">$foo </span><span style="color: #007700">= </span><span style="color: #DD0000">"example"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"foo is </span><span style="color: #0000BB">$foo</span><span style="color: #DD0000">"</span><span style="color: #007700">; </span><span style="color: #FF8000">// foo is example<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$fruits </span><span style="color: #007700">= [</span><span style="color: #DD0000">"lemon"</span><span style="color: #007700">, </span><span style="color: #DD0000">"orange"</span><span style="color: #007700">, </span><span style="color: #DD0000">"banana"</span><span style="color: #007700">];<br />print </span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">" and "</span><span style="color: #007700">, </span><span style="color: #0000BB">$fruits</span><span style="color: #007700">); </span><span style="color: #FF8000">// lemon and orange and banana<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Non-string expressions are coerced to string, even if declare(strict_types=1) is used<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">6 </span><span style="color: #007700">* </span><span style="color: #0000BB">7</span><span style="color: #007700">; </span><span style="color: #FF8000">// 42<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Because print has a return value, it can be used in expressions<br />// The following outputs "hello world"<br /></span><span style="color: #007700">if ( print </span><span style="color: #DD0000">"hello" </span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">" world"</span><span style="color: #007700">;<br />}<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// The following outputs "true"<br /></span><span style="color: #007700">( </span><span style="color: #0000BB">1 </span><span style="color: #007700">=== </span><span style="color: #0000BB">1 </span><span style="color: #007700">) ? print </span><span style="color: #DD0000">'true' </span><span style="color: #007700">: print </span><span style="color: #DD0000">'false'</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.print-notes">
  <h3 class="title">Примітки</h3>

  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <strong>Using with parentheses</strong><br />
   <p class="para">
    Surrounding the argument to <code class="literal">print</code> with parentheses will not
    raise a syntax error, and produces syntax which looks like a normal
    function call. However, this can be misleading, because the parentheses are actually
    part of the expression being output, not part of the <code class="literal">print</code>
    syntax itself.

    <div class="informalexample">
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// outputs "hello"<br /><br /></span><span style="color: #007700">print(</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// also outputs "hello", because ("hello") is a valid expression<br /><br /></span><span style="color: #007700">print(</span><span style="color: #0000BB">1 </span><span style="color: #007700">+ </span><span style="color: #0000BB">2</span><span style="color: #007700">) * </span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// outputs "9"; the parentheses cause 1+2 to be evaluated first, then 3*3<br />// the print statement sees the whole expression as one argument<br /><br /></span><span style="color: #007700">if ( print(</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">) &amp;&amp; </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br />    print </span><span style="color: #DD0000">" - inside if"</span><span style="color: #007700">;<br />}<br />else {<br />    print </span><span style="color: #DD0000">" - inside else"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">// outputs " - inside if"<br />// the expression ("hello") &amp;&amp; false is first evaluated, giving false<br />// this is coerced to the empty string "" and printed<br />// the print construct then returns 1, so code in the if block is run<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </div>
   </p>

   <p class="para">
    When using <code class="literal">print</code> in a larger expression, placing both the
    keyword and its argument in parentheses may be necessary to give the intended
    result:

    <div class="informalexample">
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if ( (print </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">) &amp;&amp; </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br />    print </span><span style="color: #DD0000">" - inside if"</span><span style="color: #007700">;<br />}<br />else {<br />    print </span><span style="color: #DD0000">" - inside else"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #FF8000">// outputs "hello - inside else"<br />// unlike the previous example, the expression (print "hello") is evaluated first<br />// after outputting "hello", print returns 1<br />// since 1 &amp;&amp; false is false, code in the else block is run<br /><br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"hello " </span><span style="color: #007700">&amp;&amp; print </span><span style="color: #DD0000">"world"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// outputs "world1"; print "world" is evaluated first,<br />// then the expression "hello " &amp;&amp; 1 is passed to the left-hand print<br /><br /></span><span style="color: #007700">(print </span><span style="color: #DD0000">"hello "</span><span style="color: #007700">) &amp;&amp; (print </span><span style="color: #DD0000">"world"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// outputs "hello world"; the parentheses force the print expressions<br />// to be evaluated before the &amp;&amp;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </div>
   </p>
  </p></blockquote>

  <blockquote class="note"><p><strong class="note">Зауваження</strong>: <span class="simpara">Оскільки це мовна
конструкція, а не функція, її не можна викликати через <a href="functions.variable-functions.php" class="link">змінні-функції</a> або <a href="functions.arguments.php#functions.named-arguments" class="link">названі параметри</a>.</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.print-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.echo.php" class="function" rel="rdfs-seeAlso">echo</a> - Output one or more strings</span></li>
    <li><span class="function"><a href="function.printf.php" class="function" rel="rdfs-seeAlso">printf()</a> - Output a formatted string</span></li>
    <li><span class="function"><a href="function.flush.php" class="function" rel="rdfs-seeAlso">flush()</a> - Flush system output buffer</span></li>
    <li><a href="language.types.string.php" class="link">Ways to specify literal strings</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>