这是使用PHP添加元素ID的正确方法吗?

i'm willing to do some css changes onmouseover and onmouseout to these divs using javascript. is it proper way to add unique id to each element using php like below.

<div id="header">
<div id="<?php echo "menu_id".$i++ ?>">home</div>
<div id="<?php echo "menu_id".$i++ ?>">contact</div>
<div id="<?php echo "menu_id".$i++ ?>">about</div>
</div>

I think that using "only" CSS in this situation is the better option. Have a look at :nth-child() (http://www.w3schools.com/cssref/sel_nth-child.asp) and :nth-of-type() (https://developer.mozilla.org/de/docs/Web/CSS/:nth-of-type)

Looks like you're dealing with dynamic content so if you need to give all of these unique ID's then this will do it. But what you're trying to achieve based on the image you provide shouldn't require each of these need a unique id though. If you let us know what you need those id's for then we may be able to give a more professional way to do it. If they're just css hooks maybe look at the nth-child(n) selector

#header div:nth-child(2) {
    background-color: rgba(100,100,100,0.4);
}

To address the question of professionalism though: professionals have to deal with some pretty funky systems and have to do things to get around those systems' limitations that probably makes their heart hurt a little. If this is one of those situations then congratulations - you're a pro!