I am stuck with a part of my code and i can't see to figure out why i get a certain result. What my goal is to loop through the array and echo this result as a string:
First Array
- validate.required
- validate.remote
Second array
shop.cart.string
Current result is:
- validate.0.required
- validate.1.remote
It returns the index from the array, how can solve this/remove this from my string?
private $translationKeys = [
'validate' => [
'required',
'remote',
'email',
'url',
'date',
'dateISO',
'number',
'digits',
'creditcard',
'equalTo',
'extension',
'maxlength',
'minlength',
'rangelength',
'range',
'max',
'min',
'step'
],
'shop' => [
'cart' => [
'string'
],
],
];
This is my function:
function listArrayRecursive($translationKeys) {
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($translationKeys), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $k => $v) {
if ($iterator->hasChildren()) {
} else {
for ($p = array(), $i = 0, $z = $iterator->getDepth(); $i <= $z; $i++) {
$p[] = $iterator->getSubIterator($i)->key();
$y = array();
foreach ($p as $value) {
array_push($y, $value);
}
}
$path = implode('.', $y);
$a[] = "$path.$v<br>";
// Here i want to echo the string
}
}
}
Second version of the function
function listArrayRecursive($translationKeys) {
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($translationKeys), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $k => $v) {
if ($iterator->hasChildren()) {
} else {
for ($p = array(), $i = 0, $z = $iterator->getDepth(); $i <= $z; $i++) {
$p[] = $iterator->getSubIterator($i)->key();
}
$path = implode('.', $p);
$a[] = "$path.$v<br>";
}
}
}
$a? all you want is the inner path to all object?