0
I have the following code:
$ms = [8,12,13];
// $ms = json_decode($ar,true); // sobrou da versão anterior da pergunta
for($i=1; $i<21; $i++)
{
foreach($ms as $obj){
if( $i == $obj ) {
echo $obj;
}
}
echo $i;
}
I need to take the array() and continue without duplication.
Output: 1 2 3 4 5 6 7 8 8 9 10 11 12 12 13 13 14 15 16 17 18 19 20
Expected: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Turns out, if I take the stretch
foreach($ms as $r){
if( $i == $obj ) {
echo ....
}
}
I get the desired result, but I need to take the value of the array and apply some Tyles if the value is found.
You want one thing and ask another. I explained in the answer the duplication of where it comes from. If the goal was just to format differently, you should have put the question (and the solution would be completely different from your loop and even simpler). That’s what we call Problemaxy. I tried to take advantage of the code and updated the answer, but I recommend reading the link to the next.
– Bacco
The question is not about PHP7 specifically, nothing in the question contains anything related to PHP7 functionalities/Features, everything described works since php5.4, so the tag should not even be PHP-7, it should be ONLY [PHP] ... PS: the last edit of the question makes no sense, a truth array inside PHP cannot be decoded again with json_decode, only strings containing json can, this code will not even run, the
$ms
will be null, obtained warning:PHP Warning: json_decode() expects parameter 1 to be string, array given
– Guilherme Nascimento