0

I'm working on something that echos from an external json page.

However I only need it to echo if ($sub = 'word') but my code simply renames all $sub's to 'word' instead of omitting the ones that don't = 'word'

<?php
$jsonurl = "http://site/page.json";
$json = file_get_contents($jsonurl);
$json_output = json_decode($json);

foreach ($json_output as $page) {
    foreach($page->levels as $level) {
        if (isset($level->sub)) {
            $sub = $level->sub;
            $no  = $level->no;
        if ($sub = 'YES!') { /*Here is the problem*/
            echo $sub . '|'. 'http://site/level/' . $no . '<br />';
        }
    }
}}
?>
Kristijan Iliev
  • 4,901
  • 10
  • 28
  • 47
Leviathan
  • 61
  • 7

1 Answers1

2

You used assign (=) instead of is equal (==)

It should go like this:

if ($sub == 'YES!') {
    echo $sub . '|'. 'http://site/level/' . $no . '<br />';
}
MaGnetas
  • 4,918
  • 4
  • 32
  • 52