Page 1 of 1

[solved]About arrays and functions.

Posted: Fri Aug 12, 2005 1:32 pm
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.. :)

Posted: Fri Aug 12, 2005 1:41 pm
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

Posted: Fri Aug 12, 2005 2:00 pm
by feyd
an array of strings to arrays? :?

example please?

Posted: Fri Aug 12, 2005 2:04 pm
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

Posted: Sun Aug 14, 2005 7:43 pm
by harrisonad
how about eval() function.
manual wrote:eval() evaluates the string given in code_str as PHP code.

Posted: Mon Aug 15, 2005 8:52 am
by dreamline
Thanks i will give it a go... :)

Posted: Mon Aug 15, 2005 10:16 am
by feyd
could just as easily, if not more straight forward, do the array mergers while creating the page information.