4
I have the json example I’m using below:
[
{
"unidade": "124",
"bloco": "Bloco B"
},
{
"unidade": "21",
"bloco": "Bloco A"
},
{
"unidade": "94",
"bloco": "Bloco A"
},
{
"unidade": "31",
"bloco": "Bloco B"
},
{
"unidade": "24",
"bloco": "Bloco B"
},
{
"unidade": "132",
"bloco": "Bloco A"
},
{
"unidade": "12",
"bloco": "Bloco A"
},
{
"unidade": "00",
"bloco": "Bloco B"
},
{
"unidade": "43",
"bloco": "Bloco B"
},
{
"unidade": "63",
"bloco": "Bloco A"
},
{
"unidade": "32",
"bloco": "Bloco B"
},
{
"unidade": "174",
"bloco": "Bloco B"
}
]
I need to sort these data so that you prioritize the Block (first the A and then the B) and then order the unit after that. I have already solved the unit, but I cannot solve the block. My code is as below:
<?php
$jsonObj = json_decode($dados);
sort($jsonObj);
foreach ($jsonObj as $buildings){
echo"$buildings->unidade" "$buildings->bloco";
}
?>
The logic worked, but I’m still struggling with Print_r(). Needed the output of the program to look like this: 11 Block A 12 Block A 13 Block A Know how I can do this?
– lucas menezes
@lucasmenezes vc want to order first the block and then the units, this?
– user148170
@Leandroalfredo That’s right Leandro, the Block has priority at the time of making the ordering. But I need it to exit without that full output of information about the array equal to this: Array ( [0] => Array ( [unit] => 11 [block] => Block A ) [1] => Array ( [unit] => 12 [block] => Block A ) [2] *As I’m still a beginner in PHP I don’t know much about handling these outputs.
– lucas menezes
ah yes, I will post new answer for you
– user148170