0
<?php

klmn("<input type='button'  value='$x'>");

function klmn($st){   
    echo "<table>";
    for ($x=1; $x<=12; $x++) 
    {
        echo "<td>".$st ." </td>";
    }
    echo "</table>";
}

when ı run this code , ı cannot see buttons values from 1 to 12

2 Answers 2

1
function klmn($st){   
    echo "<table>";
    for ($x=1; $x<=12; $x++) 
    {
        echo "<td>". str_replace('$x', $x, $st) ." </td>";
    }
    echo "</table>";
}
klmn('<input type="button"  value="$x">');
Sign up to request clarification or add additional context in comments.

Comments

0

When you pass your argument, the $x is the current var (outside the scope of your function), probably you got a notice for undefined variable.

You should do a str_replace of a placeholder

klmn("<input type='button'  value='\$x'>"); // note the backslash \$x

function klmn($st){   
    echo "<table>";
    for ($x=1; $x<=12; $x++) 
    {
        echo "<td>".str_replace('$x',$x,$st) ." </td>";
    }
    echo "</table>";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.