I’m wondering if the elements of array can ‘know’ where they are inside of an array and reference that:
Something like…
$foo = array(
'This is position ' . $this->position,
'This is position ' . $this->position,
'This is position ' . $this->position,
),
foreach($foo as $item) {
echo $item . '\n';
}
//Results:
// This is position 0
// This is position 1
// This is position 2
They can’t “reference themselves” per se, and certainly not via a
$this->positionas array elements are not necessarily objects. However, you should be tracking their position as a side-effect of iterating through the array: