当前位置: 首页>>代码示例>>PHP>>正文


PHP Set::format方法代码示例

本文整理汇总了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);
	}
开发者ID:niel,项目名称:lithium,代码行数:61,代码来源:SetTest.php


注:本文中的lithium\util\Set::format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。