Rookie PHP question sorting result of custom field
I use this to pull values from a custom field with several values:
<?php $mykey_values = get_post_custom_values('services');
foreach ( $mykey_values as $key => $val开发者_C百科ue ) {
echo "<li> $value</li>";
} ?>
I want to sort the output according to the way I have set up the values in the key (alphabetically)
$mykey_values = get_post_custom_values('services');
sort($mykey_values, SORT_STRING);
echo "<ul>\n<li>" . implode('</li><li>', $mykey_values) . "</li>\n</ul>";
Documentation for get_post_custom_values()
and sort()
.
You could use the sort()
function. See it's documentation.
精彩评论