How to convert Array into a String

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

How to convert Array into a String

Post by eshban »

I s there any way to convert PHP array in PHP STRING

like i have an array which has following info

Code: Select all

Array
(
    [0] => check_files/toplogo.png
    [1] => check_files/topphp.png
    [2] => check_files/shadow_tr.jpg
    [3] => check_files/shadow_bl.jpg
    [4] => check_files/shadow_br.jpg
)

How can i see these path in a string

thanks
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

um... each element in that array IS a string!

I might be missing your question...

Cheers,
Kieran
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Might http://nl3.php.net/manual/en/function.implode.php be of use for what you want to do?
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

Post by eshban »

i mean that how can i save the contents of array in a variable or a session variable to use it later
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

still not getting it... :?
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

wow, i didn't understand before and i surely hope that i do not know but might this be what you are asking?

Code: Select all

$string_array = array('i', 'hope', 'im', 'wrong');
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: How to convert Array into a String

Post by jmut »

eshban wrote:I s there any way to convert PHP array in PHP STRING

like i have an array which has following info

Code: Select all

Array
(
    [0] => check_files/toplogo.png
    [1] => check_files/topphp.png
    [2] => check_files/shadow_tr.jpg
    [3] => check_files/shadow_bl.jpg
    [4] => check_files/shadow_br.jpg
)

How can i see these path in a string

thanks
http://php.net/serialize
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I know what you're looking for ;)

print_r($array);

or

var_dump($array);
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

I guess you're trying to see the array elements

Use following code snippets :

Code: Select all

foreach ($array as $key=>$value){
    print $value."\n";
}

Code: Select all

for($i=0; $i<count($array); $i++){
    print $array[$i]."\n";
}
or just see all the array using print_r($array) or var_dump($array)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

<?php

session_start();

$_SESSION['MyArray'] = array('a', 'b', 'c', 'd'); 

?>
Post Reply