使用PHP将数组索引转换为字符串?

6yoyoihd  于 2022-12-02  发布在  PHP
关注(0)|答案(1)|浏览(177)
array:5 [▼
  "open" => "info"
  "on_hold" => "warning"
  "answered" => "success"
  "dev. In progress" => "success"
  "closed" => "default"
];

我需要使用这个数组并只获取String的索引,如下所示

'ticket_statuses' => [
    'open' => 'info',
    'on_hold' => 'warning',
    'answered' => 'success',
    'dev. In progress' => 'success',
    'closed' => 'default',
]

$array = config('settings.ticket_statuses');
$status = implode(',', $array);
dd($status);

当我使用implode($array)时,结果如下所示

"info,warning,success,success,default"

但我不需要这个

bqf10yzr

bqf10yzr1#

如果只想内爆索引,比如openon_hold,那么需要使用array_keys()方法:

$array = [
    'open' => 'info',
    'on_hold' => 'warning'
];

echo implode(',', array_keys($array)); // echo: open,on_hold

相关问题