Page 1 of 1

How to convert Array into a String

Posted: Wed Dec 20, 2006 12:46 am
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

Posted: Wed Dec 20, 2006 12:59 am
by Kieran Huggins
um... each element in that array IS a string!

I might be missing your question...

Cheers,
Kieran

Posted: Wed Dec 20, 2006 1:04 am
by matthijs
Might http://nl3.php.net/manual/en/function.implode.php be of use for what you want to do?

Posted: Wed Dec 20, 2006 1:04 am
by eshban
i mean that how can i save the contents of array in a variable or a session variable to use it later

Posted: Wed Dec 20, 2006 1:10 am
by Kieran Huggins
still not getting it... :?

Posted: Wed Dec 20, 2006 2:13 am
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');

Re: How to convert Array into a String

Posted: Wed Dec 20, 2006 2:18 am
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

Posted: Wed Dec 20, 2006 2:44 am
by Chris Corbyn
I know what you're looking for ;)

print_r($array);

or

var_dump($array);

Posted: Wed Dec 20, 2006 5:10 am
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)

Posted: Wed Dec 20, 2006 5:51 am
by Jenk

Code: Select all

<?php

session_start();

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

?>