convert arrays value into 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
playwright
Forum Newbie
Posts: 20
Joined: Wed Jun 02, 2010 6:11 pm

convert arrays value into string

Post 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??
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: convert arrays value into string

Post 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)

}

playwright
Forum Newbie
Posts: 20
Joined: Wed Jun 02, 2010 6:11 pm

Re: convert arrays value into string

Post 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
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: convert arrays value into string

Post 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.
playwright
Forum Newbie
Posts: 20
Joined: Wed Jun 02, 2010 6:11 pm

Re: convert arrays value into string

Post by playwright »

I used foreach ($y[$i] as $img){} and it works fine!!
Post Reply