我正在尝试从A-Z对该对象进行排序,所以如果我想获取每个名称以"m"
开头的键。
我目前拥有的东西:
$arr = (array) get_posts( $args );
$letter = 'M';
usort ($arr, function ($left, $right) {
return ((($posLeft = strpos(strtolower($left->$post_name), $letter)) === false)
? PHP_INT_MAX
: $posLeft)
- ((($posRight = strpos(strtolower($right->$post_name), $letter)) === false)
? PHP_INT_MAX
: $posRight);
});
对象:
Array
(
[0] => WP_Post Object
(
[ID] => 1
[post_name] => Mary Jane
[count] => 420
)
[1] => WP_Post Object
(
[ID] => 2
[post_name] => Johnny
[count] => 234
)
[2] => WP_Post Object
(
[ID] => 3
[post_name] => Kathy
[count] => 4354
)
....
我不知道为什么,但是它返回null