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

  • Home
  • SEARCH
  • 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 7775839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:43:33+00:00 2026-06-01T17:43:33+00:00

I have a php file in which a xml file is loaded through simplexml

  • 0

I have a php file in which a xml file is loaded through simplexml and is searched for corresponding id, everything works fine but when matching the id with the given one, it doesnt work, If I echo both of them, they are displayed but if I use if statement to match they wont match

here is my php code

  <?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$cat_xml= simplexml_load_file('http://artstack.com/sites/77/site_categories.xml'); 
$product_xml= simplexml_load_file('http://artstack.com/sites/77/site_products.xml'); 



function getcatid($product_name,$product_xml){
    foreach($product_xml as $product){
        if($product){
            if($product_name==$product->url){
                return $product->cat_id;
            }
        }
    }
}

function getcat($cat_id,$cat_xml){
    foreach($cat_xml as $cat){
        if($cat){
            if($cat_id==$cat->id){
                echo $cat['name'];
            }
            else{
                if(isset($cat->category)){
                    //sub cat
                    foreach($cat->category as $subcat){
                        if($subcat){
                            echo $cat_id." > ".$subcat->id."<br>";
                            if($cat_id==$subcat->id){
                                echo $cat_id." > ".$subcat->id."<br>";
                                exit;
                            }
                        }
                    }
                }
            }
        }       
    }   
}

getcat(getcatid($_GET['pro'],$product_xml),$cat_xml);
?>

Output is

75 > 73
75 > 74
75 > 75

but it must be

75 > 73
75 > 74
75 > 75
75 > 75
  • 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-01T17:43:34+00:00Added an answer on June 1, 2026 at 5:43 pm

    It worked after I used type casting

    if(intval($cat_id)==intval($subcat->id)){
    

    THANKS

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

Sidebar

Related Questions

I have an XML file which I'm parsing with SimpleXML in php. The first
I have an XML file which I need to parse using PHP and send
I have a PHP file which produces an Xml sitemap based on data which
I have a PHP file which edits an XML file, both on the same
I have a PHP file which echoes an XML output. However, whenever I go
I have an xml file which I'm reading with php. Currently I have the
I have a php file which prints an xml based on a MySql db.
I have a PHP file which will return something like <div id=title>Add Us On
i have one php file which process adding of record in Database fro array.
I have a php file which has a require_once Statement (?) this file is

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.