Jarosław Sitarczuk
Jarosław Sitarczuk

Reputation: 103

Change keys value in foreach PHP

It is possible to change "keys" values in foreach PHP? For example I have database like this:

https://i.sstatic.net/Ep9sl.png

And I want to get this data, and display it in:

foreach ($array as $key => $value) {
... 
}

How can I change the "keys" if i don't want do display, for example "u_group" but "Group"?

PS. Sorry for my bad english ^ ^"

Upvotes: 0

Views: 164

Answers (1)

u_mulder
u_mulder

Reputation: 54831

Create some language array, where keys are $key and value is proper text.

E.g:

$langs = ['u_group' => 'Group', 'u_other' => 'Other'];
foreach ($array as $key => $value) {
    echo 'User ' . $langs[$key] . ': ' . $value;
}

Upvotes: 2

Related Questions