Today's the first day I've really gotten stuck into creating anything from scratch in PHP7. My script skills are pretty rudimentary anyway, so I apologise in advance.
I've been looking at tutorial pages + searching Google/Stack and can't seem to find the answer to a few basic syntax questions about Multidimensional Arrays (MDAs).
The tutorials I've read show MDAs as follows:
http://webcheatsheet.com/php/multidimensional_arrays.php https://www.w3schools.com/php/php_arrays_multi.asp
$a = array(array(array("a", a2, a3),
array("b", b2, b3),
array("c", c2, c3)
),
array(array("a", a2, a3),
array("b", b2, b3),
array("c", c2, c3)
),
array(array("a", a2, a3),
array("b", b2, b3),
array("c", c2, c3)
)
);
As all the layers are simply named array and W3 only calls the parent variable with numerical values for [$row] [$col] it's unclear what solutions there are for naming and labeling elements in the array with custom handles.
Example 6 on PHP.net shows something that looks along the right lines, but it's not an exact demonstration.
Using the array shorthand which I'm more familiar with, would something like this work?
$a = [Custom1[Custom2[Custom3["a", a2, a3],
Custom3["b", b2, b3],
Custom3["c", c2, c3]
],
//**does each level require the same naming as the level above
Custom2[Custom3["a", a2, a3],
Custom3["b", b2, b3],
Custom3["c", c2, c3]
],
//**Or Are they independent and customised freely
Fred[Wez["a", a2, a3],
Otto["b", b2, b3],
Sam["c", c2, c3]
]],
];
I'm sure this is a fairly basic question, but as I said, I just couldn't seem to find an answer.
I think the concept you are looking for is simply "associative arrays".
You could create something like this (trying to use your example).
$a = [
'Custom1' => [
'Fred' => [
'Wez' => ["a", a2, a3],
'Otto' => ["b", b2, b3],
'Sam' => ["c", c2, c3]
]
]
];
To access to an element here you have to do it this way:
$element = $a['Custom1']['Fred']['Otto'][2]; // Last array is numeric
// Now $element has b3.
Remember you can't use the same index more than one time into each array. So you couldn't do this:
$a = [
'Custom1' => [
'Custom2' => [],
'Custom2' => []
]
];
Here you can read more about php arrays.
Also, as said in comments, array() is just a function you use to create the array, but your are not naming it in any way. Since PHP 5.4, you can use [] notation, which I in my opinion, keeps the code cleaner.