> On Nov 2, 2021, at 3:57 PM, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx> wrote: > > > On 02/11/2021 21:21, JEFFRY KILLEN wrote: >> >>> On Nov 2, 2021, at 1:03 PM, Tedd Sperling <tedd.sperling@xxxxxxxxx> wrote: >>> >>> >>> >>>> On Nov 2, 2021, at 2:25 PM, Christoph M. Becker <cmbecker69@xxxxxx> wrote: >>>> >>>> On 02.11.2021 at 07:24, JEFFRY KILLEN wrote: >>>>> Hello: >>>>> >>>>> I have been programming php and javascript for some time. >>>>> I have not come on a way to navigate upward in javascript >>>>> objects (it does not have associative arrays but objects are >>>>> often used in the same way associative arrays are used) >>>>> >>>>> To create a metaphor: it is like a squirrel jumps from another tree and lands on a branch. It >>>>> can find its way to the trunk and to the ground. >>>> The squirrel doesn't ask the branch how to get to the trunk or to the >>>> ground, though. Instead, it remembers its way so far. :) >>>> >>>> -- >>>> Christoph M. Becker >>> Not quite, a better analogy would be the squirrel doesn’t know on what branch his father found his mother. >>> >>> More specifically, an array inside another array doesn’t know it’s inside another array. In fact, it’s simply a memory address that can only be located via an index inside another array, which is yet another memory address. Ask any memory address where it is and it can answer you, but it can’t offer much more information other than what it is — after all, it’s just a memory address. >>> >>> If you want data to tell you what data proceeded it, then look into a double linked-list. That might solve your problem. >>> >>> Cheers, >>> >>> Tedd >>> >>> Tedd Sperling >>> tedd.sperling@xxxxxxxxx >> Yes, the squirrel analogy is a weak analogy. But like a file system, the array is a tree structure, as I >> understand it. Code or user can navigate around the file system paths using '..', which refers to the >> parent directory of the current directory. >> >> But where memory is concerned, in order to get to a particular branch, or object/array property >> the path has to already be known. Or recursive processing can hunt for a property and save >> what it finds for future reference. But that is the rub. It will have to save the property chain as >> a string. Then future reference has to use eval on the string to get the value or properties stored >> there. At least that is true for javascript and working with both, I am concerned with being able >> to translate from one to another. I presume that php works in a similar way: IE nested properties >> can be found with recusive search. But the chain of properties would have to saved as a string >> for future reference. And eval would have to be used to get to the value(s) and/or sibling properties. >> represented by the string. >> >> Or is there another way? >> >> I appreciate this exchange. Thank you >> JK > > You have your understanding of arrays wrong. An array is nothing like a tree structure, no matter how you think of them. A file tree would use a doubly linked list, as Tedd pointed out. These are effectively lists of objects, each one references it's parents, children, or siblings, within the list. > > Arrays are dumb lists, each element contains no reference to what went before, or after, and has no understanding or concept of a "parent". They're so dumb that internally PHP uses an internal pointer when traversing an array, and you can use functions like current(), next(), and reset(), to manage that pointer. > > If you need that kind of capability, then you need objects, not arrays. > > -- > Ashley Sheridan > https://www.ashleysheridan.co.uk Thank you for your guidance and suggestions; JK