Jump to content

Recommended Posts

Hello,

 

I have been assigned a PHP problem for my programming class. I'm a beginner so I am finding it really hard to figure out what to do. I got this far thanks to the internet. The problem is to take a list of students, place it in a multidimensional array, sort it, then divide it in half and place each half in two new files. I can't seem to figure out the last step. This is my code so far:

 

 

<?php

 

$students=array_map('str_getcsv', file('student.txt'));

  foreach ($student as $key => $row) $lastname [$key] = strtolower ($row[2]);

    array_multisort($lastname, SORT_ASC, $students);

 

$groupone= array_slice($students,0,10);

$grouptwo=array_slice($students,10);

      echo "<pre>" , print_r($groupone), "</pre>";

      echo "<pre>" , print_r($grouptwo), "</pre>";

 

$firstgroup=fopen(firstgroup.txt, "w");

   echo fwrite ($firstgroup,$groupone);

fclose($firstgroup);

 

At this point I get an error because I should use a string not an array to write the new file.

I don't actually know how to create a new file and export the information onto it, this is me guessing.

I would really really appreaciaite it if someone could help me out or point me in the right direction.

 

Thank you so much,

 

Camilla

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/293012-php-export-array-to-csv-file-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.