本文整理汇总了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);
}