Guest t0rtilla Posted August 15, 2006 Share Posted August 15, 2006 [code]<?phpArray ( [pnam] => gombi1 [con] => santachaos [crnk] => rfss [div] => - [time] => 15.07.2006 12:52 [mod] => 15.07.2006 22:59 [ip] => 84.50.16.93 )Array ( [pnam] => obstgrf [con] => obstgrf [crnk] => obstgrf [div] => - [time] => July 15 2006 23:30:47. [mod] => Not traced yet [ip] => Not traced yet )?>[/code]ive tryed array_multy_sort and it dint work for me. Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/ Share on other sites More sharing options...
king arthur Posted August 15, 2006 Share Posted August 15, 2006 Which key do you want to sort on? Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75136 Share on other sites More sharing options...
Daniel0 Posted August 15, 2006 Share Posted August 15, 2006 natsort, sort, ksort. There are plenty to chose from. Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75141 Share on other sites More sharing options...
Guest t0rtilla Posted August 15, 2006 Share Posted August 15, 2006 [quote author=king arthur link=topic=104356.msg416205#msg416205 date=1155653267]Which key do you want to sort on?[/quote][code][crnk][/code] Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75144 Share on other sites More sharing options...
Daniel0 Posted August 15, 2006 Share Posted August 15, 2006 Use ksort if you wan't to sort the array after the keys. (ksort = key sort) Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75146 Share on other sites More sharing options...
king arthur Posted August 15, 2006 Share Posted August 15, 2006 Okay, for multi-dimensional arrays you need a usort. Sounds scary but easy really.First you define a function:[code]<?phpfunction sort_on_crnk($x, $y){if($x['crnk'] == $y['crnk']) return 0;if($x['crnk'] < $y['crnk']) return -1;return 1;}?>[/code]Now you just do[code]usort($your_array, 'sort_on_crnk');[/code]HTH. Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75148 Share on other sites More sharing options...
Daniel0 Posted August 15, 2006 Share Posted August 15, 2006 His array is not multi-dimensional. Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75149 Share on other sites More sharing options...
king arthur Posted August 15, 2006 Share Posted August 15, 2006 Well I'm assuming he meant[code]<?php$your_array = array(array ( [pnam] => gombi1 [con] => santachaos [crnk] => rfss [div] => - [time] => 15.07.2006 12:52 [mod] => 15.07.2006 22:59 [ip] => 84.50.16.93 )array ( [pnam] => obstgrf [con] => obstgrf [crnk] => obstgrf [div] => - [time] => July 15 2006 23:30:47. [mod] => Not traced yet [ip] => Not traced yet ))?>[/code]but perhaps he didn't. Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75151 Share on other sites More sharing options...
redarrow Posted August 15, 2006 Share Posted August 15, 2006 the array is multidiensional as it has two array elements.I think lol.........................looking at king arthur example defintly. Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75152 Share on other sites More sharing options...
Guest t0rtilla Posted August 15, 2006 Share Posted August 15, 2006 [code]<?php$id_pool = array( 'pnam' => $id[1], 'con' => $id[2], 'crnk' => $id[3], 'div' => $id[4], 'time' => $id[5], 'mod' => $id[6], 'ip' => $id[7] );?>[/code]output will be (example):[code]<?phpArray ( [pnam] => gombi1 [con] => santachaos [crnk] => rfss [div] => - [time] => 15.07.2006 12:52 [mod] => 15.07.2006 22:59 [ip] => 84.50.16.93 )Array ( [pnam] => obstgrf [con] => obstgrf [crnk] => obstgrf [div] => - [time] => July 15 2006 23:30:47. [mod] => Not traced yet [ip] => Not traced yet )?>[/code]and i wanted to sort by crnk Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75159 Share on other sites More sharing options...
Daniel0 Posted August 15, 2006 Share Posted August 15, 2006 [quote author=redarrow link=topic=104356.msg416221#msg416221 date=1155654218]the array is multidiensional as it has two array elements.I think lol.........................looking at king arthur example defintly.[/quote]No, this is a multidimensional array:[code]<?php$array = array(array('hi','hi2','hi3'),'hi again',);?>[/code]Since it have more "dimensions" Quote Link to comment https://forums.phpfreaks.com/topic/17631-how-can-i-sort-an-array-like-this/#findComment-75162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.