Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
multidimensional array (3++) and explode in PHP
Old 05-10-2005, 12:52 PM multidimensional array (3++) and explode in PHP
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
Trades: 0
I want to use a multidimensional array and I get a really strange error as soon as I go into the third dimension.

PHP Code:
$pictures explode('?#$'."\n"$help); //$help contains the gallery.inc

if (count($pictures) > 1//two entries in the array indicate propper data
{
         
$pictures[count($pictures) - 2] = explode('%#$'."\n"$pictures[count($pictures) - 2]); //split last sections pictures
         
echo '<br>'.count($pictures[count($pictures) - 2]).'<br>';
         
         for (
$i 0$i count($pictures[count($pictures) - 2]); $i++)
         {
             
$pictures[count($pictures) - 2][$i] = explode('&#$'$pictures[count($pictures) - 2][$i]); //sections > pictures > a picture
         
}

The error occurs as soon as I get into the loop. I can count the array in every dimension, but can't modify it, nor am I able to echo $pictures[count($pictures) - 2][$i] O_o

To clear things up, let's just assume the input is correct and we would get something like this:

0th explode:
pictures[] //empty

1st explode:
pictures[i] //entries, the 2nd is of interest

2nd explode:
pictures[2][i] //2nd consists of numberous entries (here 3)

3rd explode:
pictures[2][i][j] //split each of their entries into half

If I echo it I get an endless loop or growing data in one of the entries. I really have no clue why this won't work and really need some help
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
 
Register now for full access!
Old 05-10-2005, 04:27 PM
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
Trades: 0
PHP Code:
        $help 'fileA&#$contentA%#$
fileB&#$contentB%#$
?#$
fileC&#$contentC%#$
fileD&#$contentD%#$
?#$
'
;
        echo 
'<h1> help </h1>'.$help.'<br> x <br>';
        
$pictures explode('?#$'."\n"$help); //$help contains the gallery.inc
echo '<h1>pictures[i]</h1>';
foreach (
$pictures as $i)
{
   echo 
'>> '.$i.'<br>';
}
        if (
count($pictures) > 1//two entries in the array indicate propper data
        
{
         
$pictures[count($pictures) - 2] = explode('%#$'."\n"$pictures[count($pictures) - 2]); //split last sections pictures
         
         
echo '<h1>pictures[count($pictures) - 2]</h1>';
for (
$i 0$i count($pictures[count($pictures) - 2]); $i++)
{
   echo 
'>> '.$pictures[count($pictures) - 2][$i].'<br>';
}
         for (
$i 0$i count($pictures[count($pictures) - 2]); $i++)
         {
          
$pictures[count($pictures) - 2][$i] = explode('&#$'$pictures[count($pictures) - 2][$i]); //sections > pictures > a picture
     
}

The output is:

help

fileA&#$contentA%#$ fileB&#$contentB%#$ ?#$ fileC&#$contentC%#$ fileD&#$contentD%#$ ?#$
x

pictures[i]

>> fileA&#$contentA%#$ fileB&#$contentB%#$
>> fileC&#$contentC%#$ fileD&#$contentD%#$
>>

pictures[count($pictures) - 2]

>> fileC&#$contentC
>> fileD&#$contentD
>>

and it repeats itself after this. Any idea why? I've had it with that stupid array, it is supposed to work but it doesn't at all O_o
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
Old 05-10-2005, 10:52 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Er, I don't think we quite understand what you are trying to do or how it is supposed to work? This is for some kind of image gallery right?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 05-11-2005, 03:18 AM
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
Trades: 0
Yes it is. It's fairly simple and will result into a three dimensional array, though not all of the elements will be asigned. The first explode will build the entries on the x-axis. The second explode will create entires on the y-axis at x=1. So far that's nothing special and we'll get a line f(x = 1,y) = x+y. Note that x=0 and x=2 won't have any values, and the explode will only effect the information in x=1 anyway (look at the string parameter).

Okay, fiarly simple. Now let's go into the third dimension by splitting each of the y elements into two values z=0 and z=1. To get all of the y rows splitted we'll just loop trugh them. Now this is where the error occurs.

If you couldn't follow the explanations so far, this visual should clear you up:

0st explode: nothing O_o

1st explode: only x-axis, echoed above as pictrues[i]

a b c

2nd explode: x-axis and y-axis, though only on x=1. Echoed above as pictures[count($pictures) - 2]

0 f 0
0 e 0
a d c

3rd explode: z-axis in x=1 and y=t 0<=t<=2 //that beeing the loop

z=0
0 g 0
0 i 0
a k c

z=1
0 h 0
0 j 0
a l c

so we go from (x,y,z)= (1,0,0) to (1,0,1) to (1,1,0) to (1,1,1) to (1,2,0) to (1,2,1). As mentioned above, the errors is the third dimension and I realy don't know why.
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
Old 05-11-2005, 10:02 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
What part in your gallery does it play?

In your second post above where you have some test output, what should it display instead?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 05-11-2005, 12:44 PM
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
Trades: 0
The outputs of the first two steps are prefectly okay. The problem is the third explode. Although nothing changed, I am not able to propperly execute the loop. The whole script runs endlessly and the first explode is somehow overwritten. The echo above showed you the steps before the loop. With the loop I get (inifinite times):

help
fileA&#$contentA%#$ fileB&#$contentB%#$ ?#$ fileC&#$contentC%#$ fileD&#$contentD%#$ ?#$
x

pictures[i]
>> fileA&#$contentA%#$ fileB&#$contentB%#$
>> fileC&#$contentC%#$ fileD&#$contentD%#$
>>

pictures[count($pictures) - 2]
>> fileC&#$contentC
>> fileD&#$contentD
>>

help
fileA&#$contentA%#$ fileB&#$contentB%#$ ?#$ fileC&#$contentC%#$ fileD&#$contentD%#$ ?#$
x

pictures[i]
>> fileA&#$contentA%#$ fileB&#$contentB%#$
>> fileC&#$contentC%#$ fileD&#$contentD%#$
>>

pictures[count($pictures) - 2]
>> fileC&#$contentC
>> fileD&#$contentD
>>

//Edit:

Okay ... I'm dumb O_o
The array itself is fine and it works perfectly. The problem with the loop was, that it was in another loop with the same counter. Now that I changed it from i to j it works as expected

Last edited by Recrehal; 05-11-2005 at 03:04 PM..
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
Reply     « Reply to multidimensional array (3++) and explode in PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43252 seconds with 12 queries