Converting to json correct way using php? -


i need o/p ["12","13"] when following json operation

i have 2 varaiables , getting these values post data

$a = $_post['cas']; $b = $_post['casty'];  $final1 = json_encode($a); $final2= json_encode($b);  $final_value = '['.$final1.','.$final2.']'; 

i getting output ["12","13"].i doing correct way in php ? other ways json object apart ?

use array this:

$array = array($_post['cas'], $_post['casty']); $final_value = json_encode($array); 

note: no need create $a , $b.

by adding json_force_object 2nd parmeter you'll key => value data normal php array. json arrays don't have keys, therefore of time json_force_object useful.

json array ["data", "data2", "data3"]  json object {0:"data", 1:"data2", 2:"data3"}     

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -