當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TimberHelper::osort方法代碼示例

本文整理匯總了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);
 }
開發者ID:ruscon,項目名稱:timber,代碼行數:18,代碼來源:test-timber-helper.php

示例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);
開發者ID:ramsaylanier,項目名稱:blades,代碼行數:31,代碼來源:archive-portfolio.php


注:本文中的TimberHelper::osort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。