简体   繁体   中英

How to convert Arrays into Strings

I am trying to make my own website, but I have a litle problem.
I've created a database so save some contact informations (like street, city, contact phone...) and I am getting these informations as arrays.
It would be awesome if you guys could help me figure out, how I can sort the arrays, or at least seperate them.

I think it would be a good idea to work with strings, but i cannot convert them. Currently I am using this right here:

$details = array('street', 'city','state', 'zipcode', 'location_name', 'country', 'date_created', 'contact_phone');
$comma_separated = implode(",", $details);

echo $comma_separated;

$details is the array with all of the info.
I am thankfull for every help :D

Your code works, the result should look like : "street,city,state,zipcode,location_name,country,date_created,contact_phone" ,

but if you want to get this informations separately, you have to stock each elements in variable, like

$data_street = $details[0];

this variable contain the first element of the array $details, so if you echo $data_street, you can show this :

street

and with an another value :

$data_state = $details[2];

$data_state return :

state

look : http://php.net/manual/en/language.types.array.php

This is an example for you:

<?php
// define string
$str = array('tinker ', 'tailor' , 'soldier' , 'spy');
echo implode(" ",$str);
?>

Output will be:

tinker tailor soldier spy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM