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 8193593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:31:49+00:00 2026-06-07T04:31:49+00:00

I’m trying to use an if statement to compare two arrays values.I am not

  • 0

I’m trying to use an if statement to compare two arrays values.I am not comparing indexes. If the values match each other, then I want to print out a value from the multidimensional array. I tried to use the solutions in :

  1. How to compare two arrays and remove matching elements from one for the next loop?

  2. array values in multidimensional array

  3. Array_values from multidimensional array

However, these examples are not quite answering my problem. I don’t need to produce a new array, I want to loop through the values, and if I have a match, echo a value to the screen.

Please see my code below, the issue is below the ‘///////////////////////////’ marks:

<?php


$str ="";


// events array
$events = array( array("PokeMon", "Hall D" , "1:00 AM"),
                 array("Sonic the Hedgehog", "WorkShop 1" , "11:00 AM"),
                 array("Tasbura", "Video 3" , "2:00 PM"),
                 array("Sailor Moon ", "Panel 4" , "6:00 PM") 
               );

// location array
$row=array(
"Arena","Hall D","Video 1","Video 2","Video 3","Video 4","Video 5","Video 6","HD Theater",
"Panel 1","Panel 2","Panel 3","Panel 4","WorkShop 1","WorkShop 2","WorkShop 3","WorkShop 4",
"Autograph 1","Autograph 2"
 );

// event start time array
$col=array(
"","9:00 AM","10:00 AM","11:00 AM","1:00 PM","2:00 PM","3:00 PM","4:00 PM","5:00 PM","6:00 PM",
"7:00 PM","8:00 PM","9:00 PM","10:00 PM","11:00 PM","12:00 AM","1:00 AM","2:00 AM",
 );

// length of  location and start time arrays 
$rowLength=count($row);
$colLength=count($col);


$str .= "<table><tr><td bgcolor='green'><table border='1' bordercolor='black'><tr>";

for($i = 0; $i < $colLength; $i++){
   $str .= "<td width='100' height='25'  bgcolor='yellow'>";
   $str .= $col[$i];
   $str .= "</td>";


}


   for ($j = 0; $j < $rowLength; $j++){
    $str .= "<tr><td width='100' height='25' bgcolor='pink'>";
    $str .= $row[$j];
    $str .= "</td> ";


        for ($k = 0; $k < $colLength-1; $k++){

            $str .= "<td width='100' height='25'  bgcolor=' #70DBDB'>";



//////////////////////Here is where I need to compare the arrays:

            if( ($row[$j]==$events[$j][1]) && ($col[$k+1]==$events[$k+1][2])){

                $str .= $events [$j][0];
///////////////////////////////////////////////////////////////////     


            }else{

            $str .= " ";

            } 

            $str .= "</td>";

        }

        $str .= " </tr>";

    }

 echo $str ."</table></td></tr></table>";

?>

This is an example of what I’m trying to create:
http://leobee.com/android/push/so/stdt2.php

Here is the code from the example:

<?php
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

$str ="";
$row=array(
'Arena',"Hall D","Video 1","Video 2","Video 3","Video 4","Video 5","Video 6","HD Theater",
"Panel 1","Panel 2","Panel 3","Panel 4","WorkShop 1","WorkShop 2","WorkShop 3","WorkShop 4",
"Autograph 1","Autograph 2"
 );

$col=array(
"","9:00 AM","10:00 AM","11:00 AM","1:00 PM","2:00 PM","3:00 PM","4:00 PM","5:00 PM","6:00 PM",
"7:00 PM","8:00 PM","9:00 PM","10:00 PM","11:00 PM","12:00 AM","1:00 AM","2:00 AM",
 );


$rowLength=count($row);
$colLength=count($col);
//echo $rowLength." ".$colLength."<br>";

$str .= "<table><tr><td bgcolor='green'><table border='1' bordercolor='black'><tr>";

for($i = 0; $i < $colLength; $i++){
   $str .= "<td width='100' height='25'  bgcolor='yellow'>";
   $str .= $col[$i];
   $str .= "</td>";



}



   for ($j = 0; $j < $rowLength; $j++){
   $str .= "<tr><td width='100' height='25' bgcolor='pink'>";
   $str .= $row[$j];


   $str .= "</td> ";


    for ($k = 0; $k < $colLength-1; $k++){
   $str .= "<td width='100' height='25'  bgcolor=' #70DBDB'>";
////////////////////////////////////////////////////////////////////////////    
        if( ($row[$j]=="Arena") && ($col[$k+1]=="9:00 AM")){

             $str .= "Poketmon";

        }else{
            $str .= "";
        }

 ///////////////////////////////////////////////////////////////////////////
   $str .= "</td>";

    }

   $str .= " </tr>";

}

 echo $str ."</table></td></tr></table>";

?>
  • 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-07T04:31:50+00:00Added an answer on June 7, 2026 at 4:31 am

    I’ve been playing with your code and arrived at the following solution. I hope you like and understand it:

    <?php
    
    // events array
    $events = array(
        array('PokeMon', 'Hall D' , '1:00 AM'),
        array('Sonic the Hedgehog', 'WorkShop 1' , '11:00 AM'),
        array('Tasbura', 'Video 3' , '2:00 PM'),
        array('Sailor Moon ', 'Panel 4' , '6:00 PM') 
    );
    
    $events_flat = array();
    
    foreach($events as $event)
    {
        $events_flat[$event[0]] = $event[1] . $event[2];
    }
    
    // location array
    $locations = array(
        'Arena', 'Hall D', 'Video 1', 'Video 2', 'Video 3',
        'Video 4', 'Video 5', 'Video 6', 'HD Theater', 'Panel 1', 
        'Panel 2', 'Panel 3', 'Panel 4', 'WorkShop 1', 'WorkShop 2',
        'WorkShop 3', 'WorkShop 4', 'Autograph 1', 'Autograph 2'
    );
    
    // event start time array
    $times = array(
        '9:00 AM', '10:00 AM', '11:00 AM', '1:00 PM', '2:00 PM',
        '3:00 PM', '4:00 PM', '5:00 PM', '6:00 PM', '7:00 PM',
        '8:00 PM', '9:00 PM', '10:00 PM', '11:00 PM', '12:00 AM',
        '1:00 AM', '2:00 AM'
    );
    
    $html = '<table><tr><td bgcolor="green"><table border="1" bordercolor="black"><tr><td></td>';
    
    foreach ($times as $time)
    {
        $html .= '<td width="100" height="25" bgcolor="yellow">';
        $html .= htmlspecialchars($time);
        $html .= '</td>';
    }
    
    foreach ($locations as $location)
    {
        $html .= '<tr><td width="100" height="25" bgcolor="pink">';
        $html .= htmlspecialchars($location);
        $html .= '</td>';
    
        foreach ($times as $time)
        {
            $html .= '<td width="100" height="25" bgcolor="#70DBDB">';
    
            $event = array_search($location . $time, $events_flat);
    
            if ($event === FALSE)
            {
                $html .= ' ';
            }
            else
            {
                $html .= htmlspecialchars($event);
            }
    
            $html .= '</td>';
        }
    
        $html .= ' </tr>';
    }
    
    $html .=  '</table></td></tr></table>';
    
    echo $html;
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.