cheesycarrion Posted June 25, 2008 Share Posted June 25, 2008 I'll post the entire script since I don't know exactly what the problem is. the error I get is "Warning: Illegal offset type in /home/cheebac8/public_html/videostest.php on line 72." I marked line 72 with a note below: <?php $mediadir = @scandir("cc08/media"); $i = 0; foreach ($mediadir as $foldername) { if ($foldername=="."||$foldername==".."||$foldername=="error_log"||$foldername==".htaccess") { // do nothing } else { $itemlist = @scandir("cc08/media/" . $foldername); foreach ($itemlist as $itemname) { if ($itemname=="."||$itemname==".."||$itemname=="error_log"||$itemname==".htaccess") { // do nothing } else { $catarray[$i] = $itemname; $i++; } } } } // print_r($catarray); // all games and videos displayed in a list foreach($catarray as $key => $val) { $explosion[$key] = explode("-",$val); } // print_r($explosion); // all media files in an array showing name, uploader and tag //////////////////////////////////////////////////////////////////////////////////////////////////////////// echo "<hr />"; foreach($explosion as $item) { if (isset($item[2])) { // tagged $tagname = $item[1]; $num_other_taggeds = count($tags[$tagname]); $tags[$tagname][$num_other_taggeds][0] = $item[0]; $tags[$tagname][$num_other_taggeds][1] = $item[1]; $tags[$tagname][$num_other_taggeds][2] = $item[2]; } else { //$tagname = "untagged"; //$num_other_taggeds = count($tags[$tagname]); //$tags[$tagname][$num_other_taggeds][0] = $item[0]; //$tags[$tagname][$num_other_taggeds][1] = $item[1]; } } // print_r($tags); // organizes items by tag category function tagged_video_section($tags) { foreach ($tags as $category) { ?> <div class="object"> <div class="object_head"> <a name="<?php echo $tags[$category][0][1] . "\">" . $tags[$category][0][1]; ?></a> </div> <div class="object_cont"> <ul> <?php $i = 0; while (isset($tags[$category][$i][0])) // line 72 { echo "<li><a href=\"" . $items[0] . "-" . $items[1] . "-" . $items[2] . "\">" . preg_replace("/_/"," ",$items[0]) . "</a></li>\n"; $i++; } //$catitems = $tags[$category]; //foreach ($catitems as $items) // { // echo "<li><a href=\"" . $items[0] . "-" . $items[1] . "-" . $items[2] . "\">" . preg_replace("/_/"," ",$items[0]) . "</a></li>\n"; // } ?> </ul> </div> </div> <?php } } tagged_video_section($tags); ?> (the code from line 78 to 82 was my first attempt, which got me the same error. I just decided to try a different approach but it didn't help me.) any help is appreciated. -- also, while I'm here, I get this other error "Warning: Invalid argument supplied for foreach() in /home/cheebac8/public_html/videostest.php on line 14" but that's nothing to worry about since it doesn't mess up the script. I'll find a way to hide it later. Quote Link to comment https://forums.phpfreaks.com/topic/111775-solved-illegal-offset-when-using-an-array/ Share on other sites More sharing options...
ratcateme Posted June 25, 2008 Share Posted June 25, 2008 line 72 has me beat i got a similar error a while back and i can't remember how i fixed it but i think i can help you on line 14 i believe the error comes form $itemlist not being an array. you could add a line like this before it if(is_array($itemlist)){ the close the if the other side of the for each Scott. Quote Link to comment https://forums.phpfreaks.com/topic/111775-solved-illegal-offset-when-using-an-array/#findComment-573850 Share on other sites More sharing options...
.josh Posted June 25, 2008 Share Posted June 25, 2008 well $tags is a 3d array so in your foreach ($tags as $category) {...} $category is an array also and you're trying to use an array as an element position. Quote Link to comment https://forums.phpfreaks.com/topic/111775-solved-illegal-offset-when-using-an-array/#findComment-573852 Share on other sites More sharing options...
ratcateme Posted June 25, 2008 Share Posted June 25, 2008 from what Crayon Violent said i would think it should be function tagged_video_section($tags) { foreach ($tags as $key => $category) { and $i = 0; while (isset($tags[$key][$i][0])) // line 72 { echo "<li><a href=\"" . $items[0] . "-" . $items[1] . "-" . $items[2] . "\">" . preg_replace("/_/"," ",$items[0]) . "</a></li>\n"; $i++; } Scott. Quote Link to comment https://forums.phpfreaks.com/topic/111775-solved-illegal-offset-when-using-an-array/#findComment-573855 Share on other sites More sharing options...
cheesycarrion Posted June 25, 2008 Author Share Posted June 25, 2008 Ok, thank's ratcateme. you're fix for line 14 also worked, and now I get what Crayon Violent meant. It works now. I also fixed some other instances where I made the same mistake. Quote Link to comment https://forums.phpfreaks.com/topic/111775-solved-illegal-offset-when-using-an-array/#findComment-573868 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.