Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:41:05+00:00 2026-06-12T02:41:05+00:00

My multi-dimensional array is working. But I cannot seem to use explode or in_array

  • 0

My multi-dimensional array is working. But I cannot seem to use explode or in_array to limit the array when calling via $_GET

<?
$shop = array(
array("red", "black", "blue", "green"),
array("orange"),
array("orange", "black"),
array("pink", "yellow")
);

foreach ($shop as $rowNumber => $row)
{
    echo "<li><b>The row number $rowNumber</b>";
        echo "<ul>";
        foreach ($row as $col) {
            if (in_array($col, explode(' and ', $_GET['filter']))){
                echo "<li>".$col."</li>";
            }
        }
        echo "</ul>";
    echo "</li>";
}

?>

If I run the script with $_GET["filter"]=="black" it displays all items – it should only display two, example this is wrong: the other rows should not appear:

enter image description here

should be this instead

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:41:06+00:00Added an answer on June 12, 2026 at 2:41 am

    Updated

    Solution 1

       <?
        
        $shop = array(
        array("1", "red", "black", "blue and green"),
        array("2", "orange"),
        array("3", "pink", "yellow", "blue and green")
        );
        
        for ($row = 0; $row < count($shop); $row++)    
         {
    
                $lis = "";
                for ($col = 0; $col < count($shop[$row]); $col++)
                    {
                         if (in_array($shop[$row][$col], explode(' and ', $_GET['filter'])) 
                            || empty($_GET['filter'])){
                            $lis .= "<li>".$col."</li>";
                         }
                    }
               if($lis != "") {
                 echo "<li><b>The row number $row</b>";
                 echo "<ul>";
                 echo $lis;
                 echo "</ul>";
                 echo "</li>";
             }
        }
        
        ?>
    

    Solution 2

    <?
    
    $shop = array(
    array("1", "red", "black", "blue and green"),
    array("2", "orange"),
    array("3", "pink", "yellow", "blue and green")
    );
    
    for ($row = 0; $row < count($shop); $row++)    
    {
        $lis = "";
        
        for ($col = 0; $col < count($shop[$row]); $col++)
        {
                if (in_array($shop[$row][$col], explode(' and ', $_GET['filter']))){
                    $lis .= "<li>".$col."</li>";
                }
        }
        
        if($lis=="") {
            
                echo "$row";
            
        } else {
            
                echo $lis;
            
        }
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m working on a multi dimensions array but i have a problem Imagine I
I have a menu being built via a multi-dimensional array. A current item is
I am trying to use array_combine to combine two multi-dimensional arrays, but somehow not
I am working in VC++ 2008, and am trying to allocate a multi-dimensional array
I'm working on something that loops over a potentially multi-dimensional array and I am
I'm working on a project of which I should store constant multi dimensional arrays.I
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a multi-dimensional array, no problem. How do I interrogator one of the
I have a multi dimensional array. The only actual values (other than other arrays)
If I have a multi dimensional array in PHP like so... [0] => Array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.