You are here: Re: Illegal offset type for array. Object to integer convertion « PHP Programming Language « IT news, forums, messages
Re: Illegal offset type for array. Object to integer convertion

Posted by Manish on 08/07/06 06:39

Got solved the problem by casting the variable.

(string) $variable;



Manish wrote:
> The code is as ...
>
>
> $folderlistfile = $path."xmlfile.xml";
>
> /*
>
> <list>
> <details id="2">
> <name>Books</name>
> <mainid>0</mainid>
> </details>
> <details id="1003">
> <name>CDs</name>
> <mainid>0</mainid>
> </details>
> </list>
>
> */
>
> $list = simplexml_load_file($folderlistfile);
>
> foreach($list as $sno=>$details) {
> if($details->isdeletable) {
> if($details->mainid) {
>
> echo "<br /> mainid = ".$details->mainid." : id =
> ".$details['id']." ";
> var_dump($details->mainid);
> $mainid = $details->mainid;
> settype($mainid, "integer");
> var_dump($mainid);
>
> // I want to save the details in an array
> //$listarr[$mainid][] = $details['id']; //Warning: Illegal offset
> type
> //$listarr[$details->mainid][] = $details['id']; //Warning: Illegal
> offset type
> }
> }
> }
>
>
> echo, var_dump will output as follow ...
>
> mainid = 0 : id = 2
> object(SimpleXMLElement)#5 (1) { [0]=> string(1) "0" }
> UNKNOWN:0
>
>
> mainid = 0 : id = 1003
> object(SimpleXMLElement)#4 (1) { [0]=> string(1) "0" }
> UNKNOWN:0
>
>
> Both of this generate the error : Warning: Illegal offset type
>
> $listarr[$mainid][] = $details['id']; //Warning: Illegal offset type
> $listarr[$details->mainid][] = $details['id']; //Warning: Illegal
> offset type
>
> and page doesn't execute furthur of this line.
>
>
> I suppose it is because the array key is an object. How do I convert it
> to integer.
>
> print_r($details->mainid) displays SimpleXMLElement Object ( [0] => 0
> )
> print_r($mainid) : nothing is displyed. even mainid = 0 : id = 2 is
> not displayed.
>
>
> System: free bsd, php 5
>
> As is mentioned in the code, I want to craete an array as
>
> either
> $listarr[$mainid][] = $details['id']; //Warning: Illegal
> offset type
> or
> $listarr[$details->mainid][] = $details['id']; //Warning:
> Illegal offset type
>
>
> Thanks.
>
> Manish

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация