Assign variables and display results

前端 未结 4 381
日久生厌
日久生厌 2021-01-29 13:01
    

i get a T_ECHO unexpected error . what is the right way of accomplishing the above task?

相关标签:
4条回答
  • 2021-01-29 13:26

    In order for you to catch any data from the function get_option you most return it from within the function itself:

    <?php
    function get_option($var){
        return $var; 
    }
    
    $num_posts = get_option($shortname.'_num_posts');
    
     //outputs what ever was returned from the function
     echo $num_posts;
    
    ?>
    
    0 讨论(0)
  • 2021-01-29 13:32

    What you are trying to do? If you want print, the code is:

    <?php 
    $somevariable = $anothervar;
    ?>
    

    If you want to assign the value of the another var, the code is:

    <?php 
    echo $anothervar;
    $somevariable = $anothervar;
    ?>
    
    0 讨论(0)
  • 2021-01-29 13:36

    It should just be

    <?php $somevariable = $anothervar; ?>
    
    0 讨论(0)
  • 2021-01-29 13:45

    I don't know what you are trying to do. echo is a language construct, so returns nothing, so its return value cannot be assigned.

    If you want to echo a value and assign it to another variable, it is best (most legible) to do it in two statements:

    <?php
    
    echo $anothervar;
    $somevariable = $anothervar;
    
    ?>
    
    0 讨论(0)
提交回复
热议问题