How to replace array value

0

This is my code currently, I would like to add the season (which I can already do) and then the episodes within that season (which I can not do).

<?php

$string = '[{"OVAS":[{"name":"01","file":"file01.mkv"},{"name":"02","file":"file02.mkv"}]},{"TEMP":[{"name":"01","file":"file01.mkv"},{"name":"02","file":"file02.mkv"}]}]';

$string = addSeason($string, 'Teste');
$string = addEpisodes($string, 'Teste', array('01', '02'), array('file01.mkv', 'file02.mkv'));

echo $string;

function addSeason($json, $name)
{
    $obj = json_decode($json, true);

    $obj[count($obj)][$name] = '';

    return json_encode($obj);
}
function addEpisodes($json, $season, $names, $files)
{
    $obj = json_decode($json, true);

    for($i=0; $i < count($names); $i++) 
    { 
        $data[$i]['name'] = $names[$i];
        $data[$i]['file'] = $files[$i];
    }

    foreach ($obj as $k => $seasons) 
    {
        foreach ($seasons as $s => $episodes) 
        {
            if($s == $season)
            {
                $episodes = $data;
            }
        }
    }

    return json_encode($obj);
}
    
asked by anonymous 23.06.2017 / 21:46

0 answers