return help with Json

Asked

Viewed 43 times

0

How to return array with these results in php

 points 
 total  25779
 HTML   1793
 CSS    2666
 Design 216
 C# 0
 Databases  0

 $minhaarray [] = array(
        "points"=>$event->total,    
        "name"=>$category->name,
);
echo minhaarray ;

obituary result

   [{"points":"387","name":null},{"points":"1","name":null}, 
   {"points":"289","name":null},{"points":"1","name":null},
   {"points":"68","name":null},{"points":"290","name":null},
   {"points":"0","name":null},{"points":"116","name":null}] 

I need this result

   points :
  nome: 6548
  nome2:65774
  nome3:78587

 assim por diante

 igual a este resultado desta pagina https://teamtreehouse.com/ethanneff.json

1 answer

1


You just have to do it from here:

$minhaarray['points'] = array(
        $category->name => $event->total 
);

echo json_encode($minhaarray, JSON_NUMERIC_CHECK);

But pay attention to the values null.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.