本文整理匯總了PHP中lithium\util\Set::format方法的典型用法代碼示例。如果您正苦於以下問題:PHP Set::format方法的具體用法?PHP Set::format怎麽用?PHP Set::format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lithium\util\Set
的用法示例。
在下文中一共展示了Set::format方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testFormat
public function testFormat() {
$data = array(
array('Person' => array(
'first_name' => 'Nate', 'last_name' => 'Abele',
'city' => 'Queens', 'state' => 'NY', 'something' => '42'
)),
array('Person' => array(
'first_name' => 'Joel', 'last_name' => 'Perras',
'city' => 'Montreal', 'state' => 'Quebec', 'something' => '{0}'
)),
array('Person' => array(
'first_name' => 'Garrett', 'last_name' => 'Woodworth',
'city' => 'Venice Beach', 'state' => 'CA', 'something' => '{1}'
))
);
$result = Set::format($data, '{1}, {0}', array('/Person/first_name', '/Person/last_name'));
$expected = array('Abele, Nate', 'Perras, Joel', 'Woodworth, Garrett');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{0}, {1}', array('/Person/last_name', '/Person/first_name'));
$this->assertEqual($expected, $result);
$result = Set::format($data, '{0}, {1}', array('/Person/city', '/Person/state'));
$expected = array('Queens, NY', 'Montreal, Quebec', 'Venice Beach, CA');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{{0}, {1}}', array('/Person/city', '/Person/state'));
$expected = array('{Queens, NY}', '{Montreal, Quebec}', '{Venice Beach, CA}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{{0}, {1}}', array(
'/Person/something', '/Person/something'
));
$expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{%2$d, %1$s}', array(
'/Person/something', '/Person/something'
));
$expected = array('{42, 42}', '{0, {0}}', '{0, {1}}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '{%1$s, %1$s}', array(
'/Person/something', '/Person/something'
));
$expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
$this->assertEqual($expected, $result);
$result = Set::format($data, '%2$d, %1$s', array(
'/Person/first_name', '/Person/something'
));
$expected = array('42, Nate', '0, Joel', '0, Garrett');
$this->assertEqual($expected, $result);
$result = Set::format($data, '%1$s, %2$d', array(
'/Person/first_name', '/Person/something'
));
$expected = array('Nate, 42', 'Joel, 0', 'Garrett, 0');
$this->assertEqual($expected, $result);
}