Answer the question
In order to leave comments, you need to log in
Is it possible to get data from an array in a shorter way?
There is an array like:
$array = [
'I' => [
'can' => [
'fly' => ['alone', 'too', 'with you'],
'eat' => ['rise', 'soup', 'your cooking'],
'dream' => ['alone', 'of you', 'again']
],
'love' => [
'you' => ['so much', ':)', 'too']
]
]
];
foreach ($array as $actor => $verbs) {
foreach ($verbs as $verb => $actions) {
foreach ($actions as $action => $words) {
foreach ($words as $word) {
echo $actor , ' ' , $verb , ' ' , $action , ' ' , $word , '<br>';
}
}
}
}
// I can fly alone
// I can fly too
// I can fly with you
// ...
// I love you too
foreach ($array as $actor => $verbs) {
foreach ($verbs as $verb => $key) {
echo $verb , '<br>';
}
}
// can
// love
Answer the question
In order to leave comments, you need to log in
Everything is fine, as an option, you can write through
php.net/array_map
or
php.net/manual/ru/function.array-walk.php
But in this case, it probably makes no sense.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question