非法抵消警告修复

时间:2016-05-04 19:47:06

标签: php

尝试在PHP中修复非法偏移警告。

以下是报告错误的代码。

foreach ( $xml->{'nowplaying-info'} as $song ) :

foreach ( $song->property as $property ) :

  foreach ( $property->attributes() as $b => $a ) :

    switch ( $a ) :
      case 'cue_title':
          $name = 'title';
          break;
      case 'track_artist_name':
          $name = 'artist';
          break;
      default:
          $name = $a;
    endswitch;

    if ( $name ) :
      $prop = strip_tags( $property->asXML() );
      if ( $name === 'title' || $name === 'artist' ) :
        $prop = ucwords( strtolower( $prop ) );
      endif;
      $property_output[$name] = $prop;
    endif;

  endforeach;

endforeach;

$property_output['time'] = strip_tags( $song['timestamp'][0] );
$song_data[] = $property_output;

endforeach;

似乎不喜欢这一行:

$property_output[$name] = $prop;

感谢对此的帮助。

1 个答案:

答案 0 :(得分:0)

$ a可能是数组对象

来自http://php.net/manual/en/language.types.array.php
数组和对象不能用作键。这样做会导致警告:非法偏移类型。

相关问题