jeudi 9 juillet 2015

PHP echo only if string match [duplicate]

This question already has an answer here:

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 />';
        }
    }
}}
?>

Aucun commentaire:

Enregistrer un commentaire