A
A
Andrey2017-08-19 14:42:29
PHP
Andrey, 2017-08-19 14:42:29

How to change response to JSON value in PHP array?

I have an answer for the name value (different names) and the status value receives the answer 1 or 2, if the answer 1 is online, 2 offline how to display the word instead of the number 1, what should be added:
<?php
$jsonData = file_get_contents ("http ://");
$json = json_decode($jsonData, true);
echo '';
$output="";
foreach($json['results'] as $results)
{
$output.="".$results['name']."
";
$output.="".$results['status']."
";
$output.="
";
}
echo $output;
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Immortal_pony, 2017-08-19
@torrentstreamru

$output .= $results['status'] == 2 ? "offline" : "online";
$output .= PHP_EOL;

instead of
$output.="".$results['status']."
";

A
Alexey, 2017-08-19
@AlexMaxTM

The question is not entirely clear. Where do you want to change the value in the PHP or JSON array?
In JSON {status: "online"}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question