3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['key1', 'value1'], ['key2', 'value2'], ['key3', 'value3'], ['key4', 'value4'], ['key5'], [null, 'value6'], ]; if(is_array($data)){ $cont = ''; foreach($data as $value){ if(count($value) === 2 && is_string($value[0]) && is_string($value[1])){ $cont .= sprintf("%s:%s%s", $value[0], $value[1], PHP_EOL); } } } var_dump($cont);
based on splKg
Output for 7.3.0 - 7.3.28, 7.4.0 - 7.4.16, 8.0.0 - 8.0.3
string(48) "key1:value1 key2:value2 key3:value3 key4:value4 "