Alex1646 Posted February 26, 2011 Share Posted February 26, 2011 I am making a website where writers can share stories. One of the fields is other stories. So I used this code to make it a array with the links in each f the items. $other_split = explode(',', $other_form); $other_int = count($other_split); $x = 0; while ($x>$other_int) { $other_link[$x] = "<a href = '$other_split[$x]'> Chapter $x </a>"; } How can I insert the data in that array into one non array variable. Quote Link to comment Share on other sites More sharing options...
SaMike Posted February 26, 2011 Share Posted February 26, 2011 You're looking for Implode(), its the exact opposite of Explode; http://fi2.php.net/manual/en/function.implode.php Quote Link to comment Share on other sites More sharing options...
SaMike Posted February 26, 2011 Share Posted February 26, 2011 $other_split = explode(',', $other_form); $other_int = count($other_split); $x = 0; while ($x>$other_int) { $other_link[$x] = "<a href = '$other_split[$x]'> Chapter $x </a>"; } $allLinks = implode("\s", $other_link); //this will put all links in string with space between each Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2011 Share Posted February 26, 2011 Don't you already have it in $other_form ? What format exactly do you want the data in? Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 26, 2011 Share Posted February 26, 2011 No need to make this harder than it needs to be. When you loop through the results, instead of putting them back into the array just to implode them into a string - ust build the string within the loop. And why in the worl would you use a while() loop instead of foreach()? $output = ''; foreach ( explode(',', $other_form) as $chapter => $href) { $output .="<a href=\"{$href}\"> Chapter {$chapter} </a>\n"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.