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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:19:07+00:00 2026-06-12T03:19:07+00:00

Here is the basic logic of what I’m trying to do that doesn’t seem

  • 0

Here is the basic logic of what I’m trying to do that doesn’t seem to be working.

  1. Loop through an array of the alphabet
  2. For each letter, loop through XML and if the program name starts with the current letter, and the major is not already in the array of output, then output a link with some data from the XML
  3. Whenever the link is output add the major to the array of output so we don’t output doubles

The problem is that even though the major is in the array the line:

if (!in_array($program->Program, $majors)) {

is always returning true, causing the doubles to be output.

Currently on the page, after every link it output I’m also outputting the entire array to visually confirm that the major exists in the array and when you get towards the bottom of the page for the major WBAN, in the first output you can look at the array above it and see that it doesn’t exist in the array so it ouputs however, the very next link output is also WBAN and you can see in the array above it that it does already exist so the if should return false and not output it…

My logic must be flawed somewhere – I’ve tried moving the array_push all around and can’t get it to work right – I need fresh eyes.

Also – correct me if I’m wrong, but the reason I can’t just purge the duplicates from the XML is because the full XML nodes aren’t duplicates – just the major is.

For example, here is the XML – only the Program and MajorDescription would be duplicated so the full XML node wouldn’t be considered a duplicate?:

<ProgramList>
    <MajorDescription>WEB ANIMATION AND DESIGN</MajorDescription>
    <Program>WBAN</Program>
    <ProgramLocations>
        <ProgramLocation>
            <Campus>Barrie</Campus>
        </ProgramLocation>
    </ProgramLocations>
    <Term>201310</Term>
</ProgramList>

Full code:

<?php 
$majors = array();
foreach ($alphabet as $l){
    $upper = strtoupper($l);                            

    foreach ($listxml->ProgramList as $program) {
        $letter = substr($program->MajorDescription, 0, 1);
        if (strcasecmp($letter, $l) == 0) {
            $count1++;
            $noprograms = false;
        }                               
    }

    if ($count1 == 0) {
        echo "<div id='$l' class='letter noprograms'>"; 
    } else {
        echo "<div id='$l' class='letter'>";
    }                           

    echo "<h2>$upper</h2>";

    foreach ($listxml->ProgramList as $program) {                             
        $letter = substr($program->MajorDescription, 0, 1);                

        if (strcasecmp($letter, $l) == 0) { 

            foreach ($majors as $major){
                echo "<p>".$major."</p>";
            }                  
            //this is where the problem is - this is always coming back true even if the major is in the array 
            if (!in_array($program->Program, $majors)) {                                    
                echo "<a href='../program/?major=".$program->Program."' class='programLink'>".$program->Program." - ".strtoupper($program->MajorDescription)."</a> - <a target='_BLANK' href='http://www.ontariocolleges.ca/SearchResults/GEORGIAN/_/N-1z1419r?Ntt=".rawurlencode($program->MajorDescription)."&Ns1=Program_Title_SORT&Ns2=0&Qo=20&SearchWithin=on'>Apply Now</a><br />";                                                                                                           
                array_push($majors, $program->Program);
            }                                                                       
            $count++;                                   
        }                               
    }
    if ($count == 0) {
        echo "<em class='noprograms'>No Programs</em><br />";
    }
    echo "</div>";                      
    $count = 0;
    $count1 = 0;
}

if ($noprograms) {
    echo '<div id="noprograms"><em>No results. Try broadening the search filters.</em></div>';
}
?>
  • 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-12T03:19:08+00:00Added an answer on June 12, 2026 at 3:19 am

    You have to cast the node to a string value:

    if (!in_array((string)$program->Program, $majors)) {
    

    And:

    array_push($majors, (string)$program->Program);
    

    It’s one of those things you have to get used to while using SimpleXML; functions that implicitly cast variables to a string don’t need this special treatment, but if you’re really paranoid I would suggest casting everything 😉

    For instance, substr() doesn’t need the cast, because it expects the first argument to be a string anyway and it will cast it automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure I'm doing something really dumb and basic here but I can't seem
Here's the basic situation: I have an OpenGL VBO that draws a 2D symbol
Here's the basic layout of a page I'm working on: alt text http://www.mfrl.org/images/pagelayout.png What
Overlooking something basic here but I am trying to set a variable and have
I’m trying to set up a pretty basic authentication logic flow with the FB
I'm trying to implement basic placeholder logic with jquery for textarea.. But there is
I have followed the article here http://chrisdail.com/2008/08/13/http-basic-authentication-with-apache-cxf-revisited/ I now have a working interceptor for
I'm working on a basic iPhone game that requires a single-screen tilemap. Nothing difficult
Beginner question here: I'm trying to understand the some basic memory management. if I'm
BASIC QUESTION I am trying to send an object through socket.emit() but the object

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.