Discussion:
Sorting through an array
Shawn McKenzie
2014-05-06 16:01:01 UTC
Permalink
array_multisort(array_column($result, 'bibleAnagramWord'), SORT_ASC,
$result);
How can I sort this array alphabetically by “ bibleAnagramWord “ ---
keeping it with the same “ reference “ and “ most_popular_views “ values?
array_multisort($bibleAnagramWord, $reference, $most_popular_views);
Cheers,
tedd
_______________
tedd sperling
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tedd Sperling
2014-05-06 14:29:59 UTC
Permalink
How can I sort this array alphabetically by “ bibleAnagramWord “ --- keeping it with the same “ reference “ and “ most_popular_views “ values?
Try:

array_multisort($bibleAnagramWord, $reference, $most_popular_views);

Cheers,

tedd

_______________
tedd sperling
***@sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ron Piggott
2014-05-06 03:26:52 UTC
Permalink
How can I sort this array alphabetically by “ bibleAnagramWord “ --- keeping it with the same “ reference “ and “ most_popular_views “ values?

$result = Array
(
[0] => Array
(
[reference] => 10
[bibleAnagramWord] => Faith
[most_popular_views] => 325
)

[1] => Array
(
[reference] => 24
[bibleAnagramWord] => Prayer [most_popular_views] => 270
)

[2] => Array
(
[reference] => 12
[bibleAnagramWord] => Joy
[most_popular_views] => 233
)

[3] => Array
(
[reference] => 4
[bibleAnagramWord] => Forgiveness
[most_popular_views] => 223
)

[4] => Array
(
[reference] => 16
[bibleAnagramWord] => Pentecost
[most_popular_views] => 168
)

[5] => Array
(
[reference] => 91
[bibleAnagramWord] => Last Supper
[most_popular_views] => 146
)

[6] => Array
(
[reference] => 44
[bibleAnagramWord] => Adopted
[most_popular_views] => 144
)

[7] => Array
(
[reference] => 5
[bibleAnagramWord] => Easter
[most_popular_views] => 139
)

[8] => Array
(
[reference] => 214
[bibleAnagramWord] => Rock
[most_popular_views] => 133
)

[9] => Array
(
[reference] => 86
[bibleAnagramWord] => Discipline
[most_popular_views] => 124
)

);

Ron Piggott



www.TheVerseOfTheDay.info
Stefan A.
2014-05-06 05:29:08 UTC
Permalink
Hi,

Something like

uasort($result, function($a, $b) { return strcmp($a['bibleAnagramWord'],
$b['bibleAnagramWord']; });

Replace strcmp with strcasecmp if you want case insensitive comparison.

Hope this helps.


On Tue, May 6, 2014 at 6:26 AM, Ron Piggott
How can I sort this array alphabetically by “ bibleAnagramWord “ ---
keeping it with the same “ reference “ and “ most_popular_views “ values?
$result = Array
(
[0] => Array
(
[reference] => 10
[bibleAnagramWord] => Faith
[most_popular_views] => 325
)
[1] => Array
(
[reference] => 24
[bibleAnagramWord] => Prayer [most_popular_views] => 270
)
[2] => Array
(
[reference] => 12
[bibleAnagramWord] => Joy
[most_popular_views] => 233
)
[3] => Array
(
[reference] => 4
[bibleAnagramWord] => Forgiveness
[most_popular_views] => 223
)
[4] => Array
(
[reference] => 16
[bibleAnagramWord] => Pentecost
[most_popular_views] => 168
)
[5] => Array
(
[reference] => 91
[bibleAnagramWord] => Last Supper
[most_popular_views] => 146
)
[6] => Array
(
[reference] => 44
[bibleAnagramWord] => Adopted
[most_popular_views] => 144
)
[7] => Array
(
[reference] => 5
[bibleAnagramWord] => Easter
[most_popular_views] => 139
)
[8] => Array
(
[reference] => 214
[bibleAnagramWord] => Rock
[most_popular_views] => 133
)
[9] => Array
(
[reference] => 86
[bibleAnagramWord] => Discipline
[most_popular_views] => 124
)
);
Ron Piggott
www.TheVerseOfTheDay.info
Ron Piggott
2014-05-06 05:37:37 UTC
Permalink
Thanks so much! Ron


Ron Piggott



www.TheVerseOfTheDay.info

Continue reading on narkive:
Loading...