Given
let inputArray = [];
$('some_selector').each(function() {
let outer, inner;
outer=$(this).parent().attr('some_property');
inner=$(this).attr('a_property');
if (!inputArray[outer])
inputArray[outer] = [];
inputArray[outer].push(inner);
});
An error is encountered during the push
function. Is it because the specific inputArray[outer]
is not declared as an array?
Also, the value of outer
is not necessarily sorted. So within the loop, outer
can sequentially have values of: "property1", "property2", "property1", "property3", "property2"...
In terms of PHP, is there something similar to:
foreach () {
$inputArray[$outer][] = $inner;
}
Thanks!