Skip to content
Advertisement

PHP array into individual php string, from SQL data

Here is a PHP code, that can be used to count data from SQL. This code displays the data in a table, I want to convert these table values (or arrays) into individual php strings. How can I do that ? I tried many methods, main issue is my lack of proper knowledge in PHP. I hope someone will help !

and the result is

I want to use php string to use it anywhere else in the script/page. For example if I use $Australia or $value[0] , the string value should be “2“, how can I achieve that ?

Advertisement

Answer

With your current approach you can create a new array in your foreach, then use that array elsewhere.

elsewhere you’d use $countries['Australia']. You could use strtolower as well so keys are easier to match up.

Another approach though may be using fetchall.

with this approach you won’t necessarily know the keys. If you want the country with most/least views though this could be easier.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement