In Java case#1:
Map m1 = new LinkedHashMap();
List l1 = new LinkedList();
m1.put("key1","val1");
m1.put("key2","val2");
l1.add(m1);
In java case#2
List l1 = new LinkedList();
l1.add("val1");
l1.add("val2");
l1.add("val3");
What’s about in PHP for these cases ?
In PHP, arrays serve as all types of containers. They can be used as maps, lists and sets.
Linked list functionality is provided through the
reset/prev/current/next/endfunctions; have a look at the “see also” section of the docs to make sure you don’t miss any of them.For map functionality you just index into the array directly; but keep in mind that array keys in PHP can only be strings or integers, and also that most of the time mixing both in the same array is not the right thing to do (although there is no technical reason not to, and there are cases where it makes sense).
SPL provides the
SplDoublyLinkedListclass, but there’s nothing in there that a simple array doesn’t also give you.