If key is known beforehand:
If you're using PHP 5.5+, you can use array_column()
to extract all the sub-arrays with plz
key:
$result = array_column($array, 'plz');
The same can be achieved using array_map()
if you're using an older version of PHP:
$result = array_map(function($sub) { return $sub['plz']; }, $array);
If key is not known beforehand:
Use array_walk_recursive()
:
$result = array();
array_walk_recursive($array, function($v) use (&$result) { $result[] = $v; });
Note that it works recursively, so it'd still work if you have more complex arrays.
Alternatively, you could use RecursiveIteratorIterator
class:
$result = array();
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
foreach($iterator as $value) {
$result[] = $value;
}
For more details, see this question: How does RecursiveIteratorIterator work in PHP?