本文整理汇总了PHP中TimberHelper::osort方法的典型用法代码示例。如果您正苦于以下问题:PHP TimberHelper::osort方法的具体用法?PHP TimberHelper::osort怎么用?PHP TimberHelper::osort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimberHelper
的用法示例。
在下文中一共展示了TimberHelper::osort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testOSort
function testOSort()
{
$michael = new stdClass();
$michael->name = 'Michael';
$michael->year = 1981;
$lauren = new stdClass();
$lauren->name = 'Lauren';
$lauren->year = 1984;
$boo = new stdClass();
$boo->name = 'Robbie';
$boo->year = 1989;
$people = array($lauren, $michael, $boo);
TimberHelper::osort($people, 'year');
$this->assertEquals('Michael', $people[0]->name);
$this->assertEquals('Lauren', $people[1]->name);
$this->assertEquals('Robbie', $people[2]->name);
$this->assertEquals(1984, $people[1]->year);
}
示例2: array
$clients = array();
$used_client_names = array();
foreach ($data['clients'] as $client) {
if (is_string($client)) {
$client_name = $client;
$new_client = new stdClass();
$new_client->client_name = $client_name;
if (!in_array($client_name, $used_client_names)) {
$used_client_names[] = $client_name;
$clients[] = $new_client;
}
} else {
if (!$client->client_name) {
$client->client_name = $client->post_title;
$client_name = $client->client_name;
if (!in_array($client_name, $used_client_names)) {
$used_client_names[] = $client_name;
$clients[] = $client;
}
} else {
$client_name = $client->client_name;
if (!in_array($client_name, $used_client_names)) {
$used_client_names[] = $client_name;
$clients[] = $client;
}
}
}
}
$data['clients'] = $clients;
TimberHelper::osort($data['clients'], 'client_name');
Timber::render('archive-portfolio.twig', $data);