Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Posts posted by benanamen

  1. Run this. If it doesn't work you may have a file permission issue.

    $_POST['fname'] = 'Sam';
    $_POST['lname'] = 'Smith';
    $_POST['sex']   = 'M';
    
    $list = array(
        array(
            $_POST['fname'],
            $_POST['lname'],
            $_POST['sex']
        )
    );
    
    $fp = fopen('test.csv', 'a');
    
    foreach ($list as $fields)
        {
        fputcsv($fp, $fields);
        }
    fclose($fp);
    
  2. We all know in PHP there are many ways to come up with the same exact result. Just for fun, lets see how many ways you can come up with to output the standard Hello World!. I did this on another forum awhile back and there are many. I will start off with the two most basic ways;

     

     

    echo "Hello, World!";

     

    print "Hello, World!";

  3.  

    Well, if we're just showing different ways to skin a cat:

    $fun = array(
     'First Word' => 'Programming',
     'Second Word' => 'in',
     'Third Word' => 'PHP',
     'Fourth Word' => 'is',
     'Fifth Word' => 'fun!',
     'Programming in PHP is fun!'
    );
     
    $fullSentence = array_pop($fun);
    foreach($fun as $key => $val) 
    {
        echo "$key, $val<br />";
    }
    echo $fullSentence;

     

     

    Interesting take, although it does require that you know that the last element is the one without a key.

  4. Just for giggles:

    $fun = array(
     'First Word' => 'Programming',
     'Second Word' => 'in',
     'Third Word' => 'PHP',
     'Fourth Word' => 'is',
     'Fifth Word' => 'fun!',
     'Programming in PHP is fun!'
    );
    
    foreach($fun as $key => $val) 
    {
        if ($val != end(array_values($fun))) {
            echo "$key, ";
        }
    
        echo "$val<br />";
    }

     

     

    I get this running your example: Only variables should be passed by reference on line number 14

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.