How can I change database data in my code to something else?

190 views Asked by At

I'm trying to change something where if the value from the database is the same as I have put in it automatically changes.

Example

<?php if $building->country is spain change to spanje?>

So I want to have that if the value from database is the same as spain I would like to have it changed to spanje. (I cannot change this data in the database since the database is not mine). Thanks in advance.

1

There are 1 answers

1
DarkBee On BEST ANSWER

A very rudimentary aproach would be to create a translation map and test if you've set a translation.
In short you set the database value as the key of the array and the output you want as the value.

With this setup you then can just test if the key (database value) has a (translation) value and output it.

<?php
    $translations = [
        'spain'     => 'spanje'
    ];

    echo $translations[strtolower($building->country)] ?? $building->country;

Keep in my mind this is case-sensitive though and a very "bad" way to solve this