Home php Error: Object of Class Stdclass Could Not Be Converted to Int

Error: Object of Class Stdclass Could Not Be Converted to Int

Author

Date

Category

Good day!

I have already written my problem with the associations of the array elements
(Addition of data from 2 arrays )

Now the problem arose where I did not expect it. I use Laravel framework.
I have 2 tables from which I receive data, and combine items in them, in fact, in what was the first question. But the problem arose that’s what. Despite the approach that I advised me, I have a mistake:

Object of Class Stdclass Could Not Be Converted to Int

Data from the base is obtained by the following type:

array (size = 1)
 0 = & gt;
  OBJECT (STDCLASS) [201]
   Public 'id_users' = & gt; INT 8.
   Public 'password' = & gt; String '$ 2y $ 10 $ 2itbbbb57ntl3i7wnmhmwhuutmfbodqptbnpdsogpcqtzakbihkkzo' (length = 60)
   Public 'email' = & gt; STRING '' (LENGTH = 0)
   Public 'Phone' = & gt; STRING '' (LENGTH = 0)
   Public 'username' = & gt; String 'Mrrino' (Length = 6)
   Public 'bl' = & gt; INT 26800.
   Public 'Exp' = & gt; int 0
   Public 'lvl' = & gt; INT 1.
   Public 'Remember_Token' = & gt; String 'yd3hsrzsh3xudziyszo0gteu9vv4lsowv2z22dbxtxcn3newjeqrv9vtexws' (length = 60)
   Public 'updated_at' = & gt; String '0000-00-00 00:00:00' (Length = 19)
   Public 'Created_at' = & gt; String '0000-00-00 00:00:00' (Length = 19)
   Public 'id' = & gt; INT 1.
   Public 'users_id_users' = & gt; INT 8.
   Public 'param28' = & gt; int 0
   Public 'param29' = & gt; int 0
   Public 'param30' = & gt; Float 0.
   Public 'param31' = & gt; Float 0.

and the second request, respectively, the same type, only with other data.
Here I need to combine them. Combined explained how, now it is not clear how to deal with this error.
Googled, did not find anything worthwhile (maybe who came across this problem and knows how to deal with it? I ask for help!


Answer 1, Authority 100%

STDCLASS returns an object, not an array, and all manipulations with the object will lead to that error that happened from me.
The problem is solved as follows:

function ObjectToArray ($ DATA)
  {
    $ Array = (Array) $ DATA;
    Foreach ($ Array AS $ Key = & gt; & amp; $ field) {
      if (IS_Object ($ field)) $ Field = $ this- & gt; ObjectToArray ($ field);
    }
    Return $ Array;
  }

And you will be happy!

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions