2
In my studies here with matrices I’m trying to highlight only the odd values (leave in bold), but I don’t understand how to do this. Below follows what I did, but I am printing both the numbers in bold and the normal ones.
<?php
$matriz = array(
array(50, 35, 44),
array(25, 11, 32),
array(53, 95, 78)
);
foreach ($matriz as $v1) {
foreach ($v1 as $v2) {
echo $v2, ' '; // imprime todos valores com espaço
if ($v2 & 1) { // se for impar
echo '<b>', $v2, '</b>';
}
}
echo '<br/>';
}
?>
where that came from
$v2 & 1
?– gmsantos
http://stackoverflow.com/questions/600202/understanding-php-ampersand-bitwise-and-operator
– phpricardo
Why did they edit my code? It was very well viewed.
– phpricardo
phpricardo, I think only the
array
is visualized better as @Rodrigorigotti did, but really is a matter of taste and opinion. Rodrigo, we should only dream when it’s an amateur posting code spaghetti. If it was my post, I would revert the keys to a new line, because it’s the style I prefer.– brasofilo
@brasofilo understood. actually I usually correct the code according to the standards that the PHP-FIG guys are defining, it’s just a stubbornness of mine :)
– Rodrigo Rigotti