[solved]About arrays and functions.

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
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

[solved]About arrays and functions.

Post by dreamline »

K, i have a little problem... Again! LOL

Here's the thing.. I want to use an array with strings to arrays.. So for example:

Code: Select all

$arr[0]='array[0]';
$arr[1]='array[1]';
$arr[2]='array[3]';

for ($i=0;$i<3;$i++)
{
$result=implode(',',$arr);
}
Nowi want to use $result in a function like array_merge_recursive($result) but that doesn't work unfortunately. Is there a way so that it works? Haven't found it in the php manual, but then again i didn't read it from front to end either.. LOL

Thanks.. :)
Last edited by dreamline on Fri Oct 21, 2005 8:53 am, edited 1 time in total.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

im sorry but what?? if you want to use array_merge_recursive on 2 arrays then do as the manual says but the code you have is doing absolutly nothing except making $result a string instead of a array 3 times which is pointless. maybe you ment somthing like

Code: Select all

$arr[0]='array[0]';
$arr[1]='array[1]';
$arr[2]='array[3]';

for ($i=0;$i<3;$i++)
{
$result[]=implode(',',$arr[$i]);
}

$result = implode(',', $result)
but i dont know
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

an array of strings to arrays? :?

example please?
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

No shiznatz, i really mean taking a string and using it in a function as if it was an array.. Let's say i've got about 20 values stacked in an array and i want to merge them all, so basically i have to type all the arrays like array_merge_recursive($arr[1],$arr[2],$arr[3]... etc).

Is there a way to use a for loop so that i can integrate all arrays into the recursive function without having to type $arr[1], $arr[2] etc. A for loop would be nice to be able to use for filling out that function..

I probably didn't give a good example but if i have about 20 arrays and add about 20 arrays i have to remember that i also have to update the recursive function. It would be easier if i could loop through the array and put it in as a string or something so that i only have to change either 1 or 2 values instead of adding 20 to the function.. Hope this clarifies a little more what i want though.. :)

:)

Oh by the way the values i've given are fictional in the arrays the actual arrays i'm merging are multidimensional arrays and consists of about 100-200 values each.

Ok for an example here we go: I'm using magpiers to subtract some RSS files, however my limited knowledge (for now) of how it exactly works makes me retrieve RSS files from an array. So basically what i do is as follows: I store links in an array and basically call the RSS function from magpiers for every single http request. It looks something like this:

Code: Select all

$rss_array[0]='hxxp://xxx.telegraaf.nl/rss/';
$rss_array[1]='hxxp://xxx.nieuws.nl/rss/';
$maxurl=2;

for ($i=0;$i<$maxurl;$i++)
 {
  $rss[$i] = fetch_rss($rss_array[$i]);
 }

$result=array_merge_recursive($rss[0],$rss[1]);
So basically i create different arrays with $rss[$i] if i add more arrays like $rss_array[] then i have to add them to the recursive function too.. That's exactly what i want to prevent because i know how many $rss[] arrays there will be created because $maxurl = 2 (this will actually end up like 15 or 20) so i want to avoid to have to type $rss[2], $rss[3],$rss[4] in the recursive function everytime i add an URL.. :)

Eventually i will ofcourse be able to inject/adjust the magpiers program to create just one array without having to merge multiple arrays...

Hope this really helps to get you the right idea.. :D
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

how about eval() function.
manual wrote:eval() evaluates the string given in code_str as PHP code.
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Thanks i will give it a go... :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

could just as easily, if not more straight forward, do the array mergers while creating the page information.
Post Reply