Jump to content

Recommended Posts

hi guys,

 

I'm using this simple polling script I found and adapted somewhere out there.

The thing works just fine, but unfortunately it does not sort the results, which makes it rather useless for my needs.

Could anyone help me with this?

This is the function it uses for reading the results from a simple txt file:

 

function readData(){

global $answers;

$rawdata = file('polldata.txt');

$numberOfAnswers = sizeof($rawdata)-1;
$count = 0;
for ($i=0; $i <= $numberOfAnswers; $i++){
	$answerData = explode(':',$rawdata[$i]);
	if (strlen(trim($answerData[0]))>0){
		$answers[$count]['text']  = $answerData[0];
		$answers[$count]['count'] = $answerData[1];
		++$count;
	}
}
}

 

so what I want to do is sort it on $answerData[1]

 

I tried


asort($answers);
foreach($answersas $key => $value)
  echo $key." ".$value." <br />"; 

 

but that returns

0 Array

1 Array

2 Array

...

 

anyone?

Link to comment
https://forums.phpfreaks.com/topic/118303-solved-sorting-a-2-dimensional-array/
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.