WatsonN Posted July 20, 2011 Share Posted July 20, 2011 I am working on a script that will take the data of one array and put it into a new one. All I'm sure about as of now it I will need a while loop. (Maybe?) I have a form where you would post a list of search terms <?php if (isset($_POST['songs'])) { $list = $_POST['songs']; $list = htmlentities($list); $list = str_replace(" ", "%20", $list); $list = explode("\n", $list); print "<pre>"; print_r($list); print "</pre>"; } else { ?> <form method="post"> <input type="submit" value="submit" /> <textarea name="songs" id="songs" /> </form> <?php } ?> Then it needs to go into this array $feed_url = array( 'feed://gdata.youtube.com/feeds/api/videos?q=$list[0]', 'feed://gdata.youtube.com/feeds/api/videos?q=$list[1]', 'feed://gdata.youtube.com/feeds/api/videos?q=$list[2]', 'feed://gdata.youtube.com/feeds/api/videos?q=$list[3]', 'feed://gdata.youtube.com/feeds/api/videos?q=$list[4]', // So on and so forth ); The problem is this first array can be as short as one or possibly up to 1000 and I just want to see if you can do it dynamically or not I know it's possible but I just can't figure it out on my own. Quote Link to comment https://forums.phpfreaks.com/topic/242417-taking-an-array-and-inserting-the-data-into-a-new-array/ Share on other sites More sharing options...
denno020 Posted July 20, 2011 Share Posted July 20, 2011 Can't you just use count() to see the size of the second array, and then use that value as the terminating value for a for loop. Something like: for($i = 0 ; $i <= count($arrayOne); $i++){ $arrayTwo = $arrayOne; } Please excuse any syntax mistakes, it's been a little while since I've done PHP programming, so I may have written that in a Java type format by mistake.. But that should be the general idea I would think. Hope that helps Denno Quote Link to comment https://forums.phpfreaks.com/topic/242417-taking-an-array-and-inserting-the-data-into-a-new-array/#findComment-1245071 Share on other sites More sharing options...
WatsonN Posted July 20, 2011 Author Share Posted July 20, 2011 do is for echoing something and you did write it correctly I tried a while loop but it used all my memory trying to do it. . . while ($data = $list) { $SongList .= 'feed://gdata.youtube.com/feeds/api/videos?q='; $SongList .= $data; $SongList .= '&orderby=relevance\n'; } Quote Link to comment https://forums.phpfreaks.com/topic/242417-taking-an-array-and-inserting-the-data-into-a-new-array/#findComment-1245140 Share on other sites More sharing options...
premiso Posted July 20, 2011 Share Posted July 20, 2011 $SongList = array(); foreach ($list as $data) { $SongList[] = 'feed://gdata.youtube.com/feeds/api/videos?q=' . $data . '&orderby=relevance'; } var_dump($SongList); Something like that? Quote Link to comment https://forums.phpfreaks.com/topic/242417-taking-an-array-and-inserting-the-data-into-a-new-array/#findComment-1245146 Share on other sites More sharing options...
denno020 Posted July 20, 2011 Share Posted July 20, 2011 I think you need a double equals? ($data == $list) Otherwise you're saying "move contents of $list into $data", and that doesn't really make sense as the condition of a while loop.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/242417-taking-an-array-and-inserting-the-data-into-a-new-array/#findComment-1245150 Share on other sites More sharing options...
WatsonN Posted July 20, 2011 Author Share Posted July 20, 2011 @premiso That was exactly it @denno020 Mo, that didn't make sense, I didn't think that through Quote Link to comment https://forums.phpfreaks.com/topic/242417-taking-an-array-and-inserting-the-data-into-a-new-array/#findComment-1245238 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.