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


PHP Set::append方法代碼示例

本文整理匯總了PHP中lithium\util\Set::append方法的典型用法代碼示例。如果您正苦於以下問題:PHP Set::append方法的具體用法?PHP Set::append怎麽用?PHP Set::append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lithium\util\Set的用法示例。


在下文中一共展示了Set::append方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testAppend

	public function testAppend() {
		$array1 = array('ModelOne' => array(
			'id' => 1001, 'field_one' => 'a1.m1.f1', 'field_two' => 'a1.m1.f2'
		));
		$array2 = array('ModelTwo' => array(
			'id' => 1002, 'field_one' => 'a2.m2.f1', 'field_two' => 'a2.m2.f2'
		));

		$result = Set::append($array1, $array2);

		$this->assertIdentical($result, $array1 + $array2);

		$array3 = array('ModelOne' => array(
			'id' => 1003, 'field_one' => 'a3.m1.f1',
			'field_two' => 'a3.m1.f2', 'field_three' => 'a3.m1.f3'
		));
		$result = Set::append($array1, $array3);

		$expected = array('ModelOne' => array(
			'id' => 1001, 'field_one' => 'a1.m1.f1',
			'field_two' => 'a1.m1.f2', 'field_three' => 'a3.m1.f3'
		));
		$this->assertIdentical($expected, $result);

		$array1 = array(
			array('ModelOne' => array(
				'id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2'
			)),
			array('ModelTwo' => array(
				'id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2'
			))
		);
		$array2 = array(
			array('ModelOne' => array(
				'id' => 1001, 'field_one' => 's2.0.m1.f1', 'field_two' => 's2.0.m1.f2'
			)),
			array('ModelTwo' => array(
				'id' => 1002, 'field_one' => 's2.1.m2.f2', 'field_two' => 's2.1.m2.f2'
			))
		);

		$result = Set::append($array1, $array2);
		$this->assertIdentical($result, $array1);

		$array3 = array(array('ModelThree' => array(
			'id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2'
		)));

		$result = Set::append($array1, $array3);
		$expected = array(
			array(
				'ModelOne' => array(
					'id' => 1001, 'field_one' => 's1.0.m1.f1', 'field_two' => 's1.0.m1.f2'
				),
				'ModelThree' => array(
					'id' => 1003, 'field_one' => 's3.0.m3.f1', 'field_two' => 's3.0.m3.f2'
				)
			),
			array('ModelTwo' => array(
				'id' => 1002, 'field_one' => 's1.1.m2.f2', 'field_two' => 's1.1.m2.f2'
			))
		);
		$this->assertIdentical($expected, $result);

		$result = Set::append($array1, array());
		$this->assertIdentical($result, $array1);

		$result = Set::append($array1, $array2);
		$this->assertIdentical($result, $array1 + $array2);

		$result = Set::append(array(), array('2'));
		$this->assertIdentical(array('2'), $result);
	}
開發者ID:niel,項目名稱:lithium,代碼行數:73,代碼來源:SetTest.php


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