Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

php:对象的数组(2)

 Share


HACK1949

Recommended Posts

php:对象的数组(2)

 

 

 

 

一、php源码

 

 

<?php
	
	class NUM
	{
		public $number="";
		public $number_class="";
	}


	class obj
	{
		public $v1 = "";
		public $v2 = "";
	}
	
	for($i=0; $i<10; $i++)
	{
		$cat[$i] = new obj;
		$nm[$i] = new NUM;
		$nu[$i] = new NUM;

		$nm[$i] -> number=$i;
		$nm[$i] -> number_class = "red";
		$nu[$i] -> number=$i*2;
		$nu[$i] -> number_class = "green";
		
		// 将“对象”赋予“成员变量”
		$cat[$i]->v1 = $nm[$i];
		$cat[$i]->v2 = $nu[$i];
	}
	
	foreach($cat as $ct)
	{
		echo "v1-number=" . $ct->v1->number ." v1-class=". $ct->v1->number_class . "\t";
		echo "v2-number=" . $ct->v2->number ." v2-class=". $ct->v2->number_class . PHP_EOL;
	}
	
?> 

  

 

 

 

二、运行结果

 

 1524989-20220806165349595-1739371983.png

 

 

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...