N
N
Nikolai Gromov2017-04-28 13:16:05
Django
Nikolai Gromov, 2017-04-28 13:16:05

How to access an element of an object that is in an array?

Hello!
I have an array like this

array(2) {
  [0]=>
  object(Shop\Entity\Category)#250 (3) {
    ["id":protected]=>
    int(13)
    ["parentId":protected]=>
    string(1) "1"
    ["category":protected]=>
    string(24) "Однополюсные"
  }
  [1]=>
  object(Shop\Entity\Category)#276 (3) {
    ["id":protected]=>
    int(14)
    ["parentId":protected]=>
    string(1) "1"
    ["category":protected]=>
    string(24) "Двухполюсные"
  }
}

Tell me how do I access the element of the "id" object?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vikholodov, 2018-05-31
@ma3xak

user_zaim(models.Model)
user_zaim  = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,  null=True, 
blank=True, default= None)

Get your naming in order. Classes are not named like that, and even more so, they should not coincide with the name of the fields, you will get confused. + remove extra spaces
OneToOneField will not work for you here, I know that there can be several loans for each user, you need the ForeignKey field.
How do you create user_zaim class objects?

M
MrTimon, 2017-04-28
@MrTimon

If the array is stuffed into the $arr variable, then most likely so But not a fact. The fact is that you have an array of objects for which all parameters are not available from outside, and if this object does not have heteros or any other functions for displaying parameters, then these parameters cannot be obtained.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question