2

i create an array and i would like to access to the value but i really don't know how :

Here is my array :

Array
(
    [0] => Array
        (
            [id] => 1
            [id_orga] => 36094152
            [nom] => Adresse externe
            [url] => https://cubber.zendesk.com/api/v2/organizations/36094152.json
            [created] => 2015-01-22 08:00:53
            [updated] => 2015-01-22 08:00:53
            [tickets] => Array
                (
                )

            [monthly] => Array
                (
                    [0] => ArrayObject Object
                        (
                            [storage:ArrayObject:private] => Array
                                (
                                    [assist] => 0
                                    [maint] => 0
                                    [total] => 0
                                )

                        )

and i would like for example to access to the value "0" in the key "assist" and change it to "1" for example and i don't know how to do it.

moskitos
  • 149
  • 1
  • 2
  • 13
  • 1
    \*Array Object is a "special" object so you can access it just like the values would be an array. To set a specific value for the Array Object inside your array just use `ArrayObject::offsetSet()` – Rizier123 Jul 13 '16 at 10:08
  • 1
    @Rizier123, oh yes you are right this is a duplicate, i didn 't see those answer, and yes it work by doing this : `$arrayOrga[0]["monthly"][0]{"assist"}`thanks ! – moskitos Jul 13 '16 at 10:14
  • Exactly. `$arrayOrga[0]["monthly"][0]` is your Array Object here and with appending `["assist"]`/`{"assist"}`(<- the same) to it you just access that particular index. So you can just call `offsetSet()` on the object, pass the index to it with the new value you want. – Rizier123 Jul 13 '16 at 10:17

1 Answers1

-1

Suppose the source array is called $myArray. Try:

$myArray[0]['monthly'][0]->storage['assist'] = 1

If that doesn't work, try:

$myArray[0]['monthly'][0]['storage']['assist'] = 1

Let me know which works so I delete the other.

BeetleJuice
  • 39,516
  • 19
  • 105
  • 165