PHP Exercise: Add special effects to specific items

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.