DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login
DiigIT » PHP »

Write a script to sort the number in asc order

By: rekha singh | 04 Feb 2010 1:18 pm

Hi All,

These are the common most questions which people ask.

1. There is a txt file with 10GB. There are numbers in each line. Write a script to sort the number in asc order.

Note: no need to use the code where u read a file in array, sort the array and write back in file.

2. echo 'hello'; echo 'world'; Modify the code on single line so that

output is 'world hello'; that means reverse of what echo displays

Thanks,

 

Comments

Script to sort the number in asc orderFor first point

<?php

$file = @fopen('yourfile' , "r");

if ($file) {

while (!feof($file) ) {

$lines[] = fgets($file, 4096);

}

fclose($file) ;

}

?>

then sort and write back.

 

By: rekha singh | 04 Feb 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move