Page 1 of 1

convert arrays value into string

Posted: Wed Jul 14, 2010 10:12 am
by playwright
hello!! is there any function that can convert every single value of an array into string??? I tried implode() but i think it converts the whole array into one string..maybe i'm wrong..this is what i'm trying to do..

preg_match_all('/<img src\=[\"](.*?)[\"] (.*?)>/si',$x, $y);
$count = count($y;
for ($i=1;$i<=$count;$i++){
$keys = implode("+",$y[$i]);
$new = substr($keys,30,7);
}

any ideas??

Re: convert arrays value into string

Posted: Wed Jul 14, 2010 10:21 am
by buckit
I'm not sure I completely follow what you are trying to accomplish...

your preg_match is creating an array (obviously)

so

Code: Select all

foreach($y as $key=>$val){
//do something with the array key ($key) and do something with the keys value ($val)

}


Re: convert arrays value into string

Posted: Wed Jul 14, 2010 10:29 am
by playwright
i tried this way as you wrote:
preg_match_all('/<img src\=[\"](.*?)[\"] (.*?)>/si',$noquotes, $matches);
foreach ($matches as $key=>$val){
$new1 = implode("+",$val);
$new = substr($new1,30,7);
echo $new;
}

Actually it does the same thing when i use substr() it gives me only result..I'm thinking that maybe implode() converts the whole array into one string..if i dont use implode() it gives me an error : substr() expects parameter 1 to be string, array given

Re: convert arrays value into string

Posted: Wed Jul 14, 2010 11:01 am
by buckit
what is an example value of $val and what are you trying to do with it?

you shouldnt use implode() on $val as $val is not an array... $val is a string value of the array key.

Re: convert arrays value into string

Posted: Wed Jul 14, 2010 11:13 am
by playwright
I used foreach ($y[$i] as $img){} and it works fine!!