jonybhi Posted July 20, 2011 Share Posted July 20, 2011 Hello, I've a text file containing data for images its like: 1:thumb_1.gif:large_1.gif 8:thumb_2.gif:large_2.gif 5:thumb_3.gif:large_3.gif Array 0 represent views, Array 1 represents thumbnail and Array 2 represents full size image. I'm using the following code to display images: <?php $file_handle = fopen("datafile.txt", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('/n', $line_of_text); foreach($parts as $gallery_data) { $data = preg_split('/:/', $gallery_data); ?> <img src="<?php echo $data[0]; ?>" width="150" height="150"> <?php } } fclose($file_handle); ?> the above code displays the images in text file order. I'd like it to display most viewd image first, for which the data in variable $line_of_text should be: 8:thumb_2.gif:large_2.gif 5:thumb_3.gif:large_3.gif 1:thumb_1.gif:large_1.gif so the question is, how can i arrange it? Link to comment https://forums.phpfreaks.com/topic/242431-order-a-multiple-line-variable/ Share on other sites More sharing options...
dragon_sa Posted July 20, 2011 Share Posted July 20, 2011 check out arsort here http://www.php.net/manual/en/function.arsort.php Link to comment https://forums.phpfreaks.com/topic/242431-order-a-multiple-line-variable/#findComment-1245132 Share on other sites More sharing options...
jonybhi Posted July 20, 2011 Author Share Posted July 20, 2011 i referred to your link, but I'm not getting it, any further help plz Link to comment https://forums.phpfreaks.com/topic/242431-order-a-multiple-line-variable/#findComment-1245185 Share on other sites More sharing options...
AbraCadaver Posted July 20, 2011 Share Posted July 20, 2011 Should be easier (not tested): foreach(file('datafile.txt') as $key => $value) { $data[$key] = explode(':', $value); $view[$key] = $data[$key][0]; } array_multisort($view, SORT_DESC, $data); Link to comment https://forums.phpfreaks.com/topic/242431-order-a-multiple-line-variable/#findComment-1245189 Share on other sites More sharing options...
jonybhi Posted July 21, 2011 Author Share Posted July 21, 2011 Should be easier (not tested): foreach(file('datafile.txt') as $key => $value) { $data[$key] = explode(':', $value); $view[$key] = $data[$key][0]; } array_multisort($view, SORT_DESC, $data); I'm not getting this, please help.. Link to comment https://forums.phpfreaks.com/topic/242431-order-a-multiple-line-variable/#findComment-1245495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.