Hello,

I have an array that returns city and state in this format: Detroit,MI

I want it to be shown as Michigan/Detroit

is there any way of doing this?

Here is my foreach code:

foreach ($i['popularCities'] as $a => $value)
                {
                echo '<li>' . $value . '</li>' . PHP_EOL;
                }

Thanks

Recommended Answers

All 4 Replies

return the value before the index.

I think i need a str_replace(); code to make it work, but i cannot figure it out

when you do

var_dump($i['popularCities'] );

what do you get?

Member Avatar for diafol

How is your code going to know that MI = Michigan? Do you have an array like:

array('MI'=>'Michigan',...[all other states])
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.