Home > Software engineering >  PHP function return string and variable
PHP function return string and variable

Time:06-16

I have a PHP function that has to return some string and print variables into the string. Now the function returns a string but does not print variable value.

function listShortcode ($id) {
    $i = $id;
    $html = "<h2>List number";
    $html .= $id;
    $html .= "</h2> <p>other</p>";
    
    return $html;
}

CodePudding user response:

Hi Ashot I tried it in online code editor and it works fine. enter image description here

CodePudding user response:

What about

function listShortcode ($id) {
    $i = $id;
    $html = "<h2>List number";
    $html .= $i;
    $html .= "</h2> <p>other</p>";
    
    return $html;
}

CodePudding user response:

use signle quot's

function listShortcode ($id) {
$i = $id;
$html = '<h2>List number';
$html .= $id;
$html .= '</h2> <p>other</p>';

return $html;}
  • Related