警告:非法字符串偏移 - php

时间:2018-02-21 18:59:41

标签: php

代码

$chandet = channeldetails(12567);
print_r($chandet);
foreach ((array) $chandet as $det) {
    echo $det . "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    print_r($det);
    // exibit 1 for this print-r output
    foreach ((array) $det['videos'] as $ails) {
        foreach ((array) $ails as $value) {
            echo $value . "<br>";
        }
    }

}

我收到此错误Warning: Illegal string offset 'videos'

我似乎无法修复它我尝试使用$det[0]这样的数值,但它仍然不起作用似乎我的所有代码都是正确的我有研究但没有#&# 39;找不到我正在使用print_r来查看数组中是否有任何违规但是没有。

excbit 1:数组 (

[videos] => Array
    (
        [0] => Array
            (
                [channel_video_id] => 3433
                [channel_id] => 342333
                [video] => pathtofile/something.mp4
                [start] => 0
                [length] => -1
                [sort_order] => 0
                [is_ad] => 0
            )

        [1] => Array
            (
                [channel_video_id] => 2364
                [channel_id] => 342333
                [video] => pathtofile/something.mp4
                [start] => 0
                [length] => -1
                [sort_order] => 1
                [is_ad] => 0
            )

    )

      )

第一次print_r结果

Array
(
    [channel] => Array
        (
            [details] => Array
                (
                    [channel_id] => 3434
                    [cdn_id] => 343
                    [channel_name] => testing
                    [server_ip] => 93.167.671.93
                    [app] => testing-chorigin
                    [app_inst] => live
                    [stream] => testing
                    [repeat] => 1
                    [metadata] => 0
                    [scheduled] => 2018-02-20 10:40:00
                    [last_modified] => 2018-02-20 22:40:00
                    [active] => 1
                    [show_video_names] => 0
                    [overlay_message] => 
                    [closed_on] => 
                    [reason] => 
                )

            [videos] => Array
                (
                    [0] => Array
                        (
                            [channel_video_id] => 344
                            [channel_id] => 344
                            [video] => myvid
                            [start] => 0
                            [length] => -1
                            [sort_order] => 0
                            [is_ad] => 0
                        )

                    [1] => Array
                        (
                            [channel_video_id] => 324
                            [channel_id] => 344
                            [video] => myvid
                            [start] => 0
                            [length] => -1
                            [sort_order] => 1
                            [is_ad] => 0
                        )

                )

        )

    [status] => success
    [message] => channel Found
)

谢谢

1 个答案:

答案 0 :(得分:2)

更新已编辑的问题:

echo 'Printing data <br />' . PHP_EOL;
echo $chandet['status'] . '<br />' . PHP_EOL;
echo $chandet['message'] . '<br />' . PHP_EOL;


foreach( $chandet['channel']['details'] as $key => $value ) {
  echo $key . ' ' . $value . '<br />' . PHP_EOL;
}

foreach( $chandet['channel']['videos'] as $video) {
  foreach( $video as $key => $value ) {
    echo $key . ' ' . $value . '<br />' . PHP_EOL;
  }
}