foreach ($wishlist as $test2)
echo $test2 . '';

How can I place the results of echo $test2 . ''; in a variable?

    You may have already considered this, but here goes:

    <?php
    
    $array = array('a', 'b', 'c');
    
    foreach ($array as $value)
    {
        $array[] = $value;
    }
    // show that we can extract elements
    echo $array[0]."<br>";
    echo $array[1]."<br>"; 
    echo $array[2]."<br>";
    
    // assign those elements to vars
    $a = $array[0];
    $b = $array[1];
    $c = $array[2];
    
    // echo the vars
    echo $a."<br>";
    echo $b."<br>";
    echo $c."<br>";
    
    ?>
    

      Hmmm....

      Well what I really need to do is get the results of

      echo $test2 . '';

      in some form of a variable so that I can use it in a query.

      So I can have a query like

      INSERT INTO test (property) VALUES ('echo $test2 . ''')

        You could use

        foreach ($wishlist as $test2)
        {
            $tmp=$test2 . '';
            // do something with $tmp . . .
        } 

          I'm not clear on why you're usring the echo before the variable name in your insert... why not just insert the variable?

            
            foreach ($wishlist as $test2) 
            { 
            $q=" INSERT INTO test (property) VALUES ('$test2') ";
            
            } 
            
              Write a Reply...