Temuulen Optimistic Temuulen Optimistic - 10 months ago 27
JSON Question

PHP JSON color change depending on value

I want to change the number color depends on number value from json object.

Example this is my json file.

"status": "ok",
"meta": {
"count": 1
"data": {
"521997295": {
"global_rating": 4647

If the global rating number is lower than 1000 i want to display green. If it is higher red ect... It must be in php script. How do i do that? Thank you for help.


First, you will need to use json_decode() function to read the JSON data as an object or array.

Then from the object or array, you will need to get the value of 'global_rating'.

After that, you can use conditional logic to do the things as you want. For example:

if($global_rating < 1000) {
    // font-color = green
} else {
    // font-color = red