Questions tagged [arrayobject]

ArrayObject class allows objects to work as arrays in PHP. Properties of the object have their normal functionality when accessed as list. Use this tag for questions related to arrayobject.

ArrayObject class allows objects to work as arrays in PHP. Properties of the object have their normal functionality when accessed as list. Use this tag for questions related to arrayobject.

ArrayObject is an object that is designed to behave exactly like an array. If that seems confusing, don’t worry, it’s not. ArrayObject is an object. It follows all the rules of how objects work. But it’s designed to implicitly behave like an array for all intents and purposes, including being used in a foreach loop, and accessing its properties just like you would access the values in an array. Consider the following code sample:

<?php

 $array = array('one', 'two', 'three');

 $arrayObj = new ArrayObject($array);

 var_dump(($array[0] == $arrayObj[0])); // Outputs true.

?>

For information on object and array please check and

Reference

337 questions
4
votes
2 answers

Destroying an ArrayObject in PHP

I was looking for the __destroy() method in ArrayObject but found no implementation. If I set the variable containing an ArrayObject to NULL, will it correctly destroy all the objects stored in it and free memory? Or should I iterate the ArrayObject…
Gerardo
  • 1,928
  • 4
  • 24
  • 34
4
votes
3 answers

adding an object into an array of objects with a function?

I understand the commands needed to add an object to an array. I know its array.push(object). However, say I have this array of objects: const artists = [{ "rank": 1, "name": "Rakim", "year": 1985, "album": "Paid in Full", }, …
wettems
  • 41
  • 2
4
votes
0 answers

How to get "Subject" value from Gmail API response?

Below is the sample response I get from Gmail API payload headers. How do I get the "Subject" value from the below array of objects. I do not want to use response.get(index).getValue().toString(); as the index will change from message to message. …
Anoop Naik
  • 335
  • 7
  • 15
4
votes
1 answer

Php - empty ArrayObject

The ArrayObject class allows objects to work as arrays. When I check if an ArrayObject is empty, though, the result is always false echo empty(new ArrayObject()); // returns false Wouldn't it be more coherent with the behavior of an empty array []…
marcosh
  • 8,780
  • 5
  • 44
  • 74
4
votes
0 answers

PHP: phpdoc for elements of a class which extends ArrayObject

I have a class which is a simple extension of the ArrayObject class: /** * what to put here? :) */ class Collection extends \ArrayObject { /** * @param Item */ public function add(Item $item) { $this->append($item); …
ayeo
  • 482
  • 1
  • 4
  • 16
4
votes
1 answer

How to access $array[@key] value

I am working with expedia API's and its working well but I don't know how to access this special type of array key. Response is given below $response = stdClass Object ( [@size] => 1 [@activePropertyCount] => 144 [city] => 1 …
vikujangid
  • 728
  • 3
  • 8
  • 19
4
votes
3 answers

ArrayObject doesn't allow me to unset a value, while iterating over it

I've got this notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in /var/www... which is produced by this code, at the begining of the foreach loop. Together with the notice, the foreach loop…
enrey
  • 1,621
  • 1
  • 15
  • 29
4
votes
3 answers

Filter ArrayObject (PHP)

I have my data in ArrayObject, simply representing an array. I need to filter the data, function array_filter() would work great. However, it does not work with ArrayObject as argument. What's the best way to treat with this? Is there any standard…
Pavel S.
  • 11,892
  • 18
  • 75
  • 113
3
votes
1 answer

PHP ArrayObject inner workings

Where can I find the ArrayObject's complete source code (in PHP)? What I dont understand is why you can use the "arrow" when add an element to your ArrayObject, for example: $a = new ArrayObject(); $a['arr'] = 'array data'; …
Filkor
  • 642
  • 6
  • 18
3
votes
4 answers

ArrayObject iteration

Problem: ArrayObject works as expected when the values are set or read manually, but when using a function (foreach for example) to iterate over it, things gets wicked. It doesn't call the offset* methods that I have defined but instead uses the…
user529649
3
votes
0 answers

React updating a state array that is nested within array of objects

So I'm feeling somewhat confident on updating the array of objects when it's just array of objects using map and the spread function. However, where I'm stuck on is updating an array that is within array of objects. Here's the example. I have a…
Spork
  • 65
  • 5
3
votes
2 answers

Change keys of array object after inserting in the middle/first of array object

I am working on an Excel-like application, but I am having problems with a multi-dimensional array. I have array of columns that looks like this: var columns = [ {A: {binding: "A",header: "A"}, {B: {binding: "B",header: "B"}, {C: {binding:…
hafizh
  • 33
  • 1
  • 3
3
votes
1 answer

How to get selected checkbox table row with each td data attributes to array objects?

Here is my Html code block I loaded table data from rest api and i want to get array object from each row td data attributes selected using the checkbox
3
votes
2 answers

transform array of object into new array following with its child

i have an array like this var data = [ { name: "Movies", info: "category_name", content: [ { name: "Interstellar", info: "category_data" }, { name: "Dark Knight", info: "category_data" }, ] …
Khadam Ikhwanus
  • 302
  • 2
  • 10
3
votes
2 answers

Get values from JSON array in PHP with the following format?

I have got this array from the Android developer whom I am working with and I have to get the values of the key name from the following array: [ { "data":"[{\"name\":\"step 1…
Shubham
  • 43
  • 6
1
2
3
22 23