在单行上回显数组的键? PHP

时间:2017-01-04 18:03:26

标签: php

如何在一行上获得数组键的回声?

[The] => s
[revelation] => b
[that] => z
[the] => d
[Star] => e  
[Wars] => h    

结果:

<p>The revelation that the Star Wars.</p>

1 个答案:

答案 0 :(得分:3)

非常简单:

$myArray = [
    'The' => 's',
    'revelation' => 'b',
    'that' => 'z',
    'the' => 'd',
    'Star' => 'e',
    'Wars' => 'h',
];

echo implode(' ', array_keys($myArray));

这基本上得到一个键的数组,然后用空格内容。