“Cannot use string offset as an array” error

前端 未结 3 1399
广开言路
广开言路 2020-12-07 03:57

Can\'t figure what is wrong here. Read what folks are saying here: http://informationideas.com/news/2006/06/14/fatal-error-cannot-use-string-offset-as-an-array-in/ and her

相关标签:
3条回答
  • 2020-12-07 04:49

    My bet is that either

    • $entries is not an array
    • one or multiple of $e are not arrays

    try

    foreach ( $entries as $e ) {
        $info = array(); // added to see if pre-declaration helps
        if (is_array($e)) // only go on if $e is actually an array
        $info = array( $e[ 'title' ], 
                       $e[ 'gd:when attr' ][ 'startTime' ], 
                       $e[ 'gd:where attr' ][ 'valueString' ], 
                       $e[ 'content' ] );
    }
    

    If you want to do it really properly, you check for each key of $e ("startTime" and so on) first using isset() or array_key_exists().

    0 讨论(0)
  • 2020-12-07 04:50

    you dont need the foreach

    $info = array( 
                      $entries[ 'title' ], 
                      $entries[ 'gd:when attr' ][ 'startTime' ], 
                      $entries[ 'gd:where attr' ][ 'valueString' ], 
                      $entries[ 'content' ] 
                     );
    
    0 讨论(0)
  • 2020-12-07 04:58

    To overcome this error at first check whether its an array or net then do array elements manipulat

    0 讨论(0)
提交回复
热议问题