how to encode json data in php

Encode: json_encode( array(‘id’=>$i, ‘name’ => $row[‘name’]) ); Or $arr = array( ‘id’=>$i, ‘name’ => $row[‘name’], ); json_encode($arr); Decode: $decoded = json_decode($arr);