The boss said:
I just fill in the text box 1|3, the 1th and 3rd items should be labeled!
Thinking Process:
With important information 1 and 3, and the cycle of the product $key in order automatically increment, then as long as the key and information matching, the judgment of the product tagging, this can be used to position information into an array, through In_array judge $key this position in the position is not in the array, (in practice we start from 1, The loop starts at 0, so you need to add 1 to the $key on the match)
<! DOCTYPE html>#000;text-align:center;width:200px;height:200px;float:left;margin:10px;line-height:200px;}</style>PHP//Location Text$str= "1|3";//Position array by | splitting$markarr=$str?Explode("|",$str):"";//Commodity Group$arr=Array( Array("Name" = "Productone", "Price" =>10),Array("Name" = "Producttwo", "Price" =>20),Array("Name" = "Productthree", "Price" =>30),Array("Name" = "Productfour", "Price" =>40));//Recycling Productsforeach($arr as $key=$item){ Echo' <div class= ' box > '; if(In_array($key+1,$markarr)){ Echo"This item is labeled"; } Echo' </div> ';} ?></body>PHP Exercise: Add special effects to specific items