Cannot use string offset as an array in php

前端 未结 10 862
南方客
南方客 2020-11-29 06:35

I\'m trying to simulate this error with a sample php code but haven\'t been successful. Any help would be great.

\"Cannot use string offset as an array\"

10条回答
  •  长情又很酷
    2020-11-29 06:51

    I was having this error and a was nuts

    my code was

    $aux_users='';
    
    foreach ($usuarios['a'] as $iterador) { 
    #code
    if ( is_numeric($consultores[0]->ganancia) ) {
        $aux_users[$iterador]['ganancia']=round($consultores[0]->ganancia,2);
      }
    }
    

    after changing $aux_users=''; to $aux_users=array();

    it happen to my in php 7.2 (in production server!) but was working on php 5.6 and php 7.0.30 so be aware! and thanks to Young Michael, i hope it helps you too!

提交回复
热议问题