0

Bellow are Dynamic Output for E-ticket

{
   charting: "CNP"
}

To - chart not prepared

{
    charting: "CP"
}

To - chart prepared

How to change this output in PHP

Thanks

4
  • can you add more details that how do you get this output and what is the source, what you have tried Commented Jul 28, 2015 at 6:34
  • I use third party API and its showing this status for chart prepared or not with only "CNP" and "CP" I need to convert both in full text like - chart not prepared and chart prepared version Commented Jul 28, 2015 at 6:36
  • Can you add the code from where you got those responses? Commented Jul 28, 2015 at 6:41
  • Sorry I can't :( That not public API Commented Jul 28, 2015 at 6:42

1 Answer 1

1

You can use json_decode() to get the data, change the data as you need, and use json_encode() to encode it again.

e.g

<?php
$json = '{
   "charting": "CNP"
}';
$phpArray = json_decode($json, true);


if($phpArray['charting'] == 'CP'){
    $phpArray['charting'] = 'chart prepared';
}else if($phpArray['charting'] == 'CNP'){
    $phpArray['charting'] = 'chart not prepared';
}


echo json_encode($phpArray);
?>
Sign up to request clarification or add additional context in comments.

3 Comments

This both values are not same every time so how could I encode it?
I edited my post @OliviaNielsen, is it what you are looking for?
You're welcome. Please consider marking your question as solved if everything works fine for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.