在循环中显示PHP数组值

时间:2014-08-28 16:22:53

标签: php

我有这个值数组

$statuses = array(
'pending' => 'Pending', 
'paid' => 'Received', 
'failed' => 'Failed', 
'withdrawn' => 'Paid Out', 
'refunded' => 'Refunded'
);

然后我运行一个foreach循环:

foreach (array_reverse($output) as $row) {
    echo $row->status;
}

当我在循环中回显$row->status时,如果它等于withdrawn,它是否会显示Paid Out(就像在我的数组中一样)?

1 个答案:

答案 0 :(得分:0)

是的,它绝对可以。只要$row->status的结果与key中的$statuses保持一致

echo $statuses[$row->status];