/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Mixed Array Sort+Concatenation Problem

Hi Mates,

I want to sort the values in descending order which is stored in a array.when I have only the following integer values then sorting is taking place correctly.But the proble occurs when there is a mixed type.

Lets see

$sum=$sum.”,”.”Monday”.”,”.”Morning”;//$sum=12,Monday,Morning
$sum1=$sum1.”,”.”Tuesday”.”,”.”Morning”;/ /$sum1=14,Monday,Morning
$sum2=$sum2.”,”.”Wednesday”.”,”.”Morning”;//$sum2=11,Monday,Morning

$sumarr=array($sum,$sum1,$sum2);
sort($sumarr);
foreach($sumarr as $key=>$value)
{

//echo “Key: $key; Value: $value<br />n”;
list($h,$d,$ts)=explode(“,”,$value);

}

also please tell me how can i keep $sum.”,”.”Monday”.”,”.”Morning” inside a “”.

that means i want to keep it as

$sum=”$sum.”,”.”Monday”.”,”.”Morning””;//But this is giving error i think its a concatenation problem.

Please suggest me a suitable way.

Thanks in advance for your co-operation.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 09.2006 — Could you not simply do...
[code=php]
$sum = "$sum,Monday,Morning";
[/code]
...?
Copy linkTweet thisAlerts:
@raj_2006authorJul 09.2006 — yes it can be simple as you said......going dull day by day..... ?


but the first problem is not going.I mean i cant sort mixed values(numeric+text)

$sum="12,monday,evening";//this way i cant do sorting

what are the other ways so that i can sort both of numeric and text all at once......plz suggest

Thanks

Raj
Copy linkTweet thisAlerts:
@bokehJul 09.2006 — There are probably a million ways to sort that so you need to explain the desired result and surrounding info.
Copy linkTweet thisAlerts:
@NogDogJul 10.2006 — Without knowing exactly how you want them sorted, by best guess is that maybe you should use the natsort() function instead of sort().
Copy linkTweet thisAlerts:
@raj_2006authorJul 10.2006 — Hi Mates

Thanks for your suggestions......The sorting should be in this way

//say the variables are like this

$sum=$sum.","."Tuesday".","."Morning";//$sum=12,Tuesday,Morning

$sum1=$sum1.","."Tuesday".","."Evening";/ /$sum1=14,Monday,Evening

$sum2=$sum2.","."Friday".","."Afternoon";//$sum2=11,Friday,Afternoon

$sumarr=array($sum,$sum1,$sum2);

sort($sumarr);

foreach($sumarr as $key=>$value)

{

//echo "Key: $key; Value: $value<br />n";

list($h,$d,$ts)=explode(",",$value);

}

//Display should be in this way

Monday Evening 14

Tuesday Morning 12

Friday Afternoon 11

I mean in descending order i like to display the table.

Thanks

Raj
Copy linkTweet thisAlerts:
@raj_2006authorJul 10.2006 — Hey Mates.....


yo yo yo....its solved....i did in this way

$sumarr=array($sum,$sum1,$sum2,$sum3,$sum4,$sum5,$sum6,$sum7,$sum8,$sum9,$sum10,$sum11,$sum12,$sum13,$sum14,$sum15,$sum16,$sum17,$sum18,$sum19,$sum20);

natsort($sumarr);

$sumarr = array_reverse($sumarr, true);

foreach($sumarr as $key=>$value)

{


//echo "Key: $key; Value: $value<br />n";

list($h,$d,$ts)=explode(",",$value);

}

Just reversed the output of natsort by array_reverse........... ?

Thank to all of you for your help............... ?

luv..................Raj
×

Success!

Help @raj_2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...