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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:27:05+00:00 2026-06-17T23:27:05+00:00

i have come to this strange issue. i am getting values from array and

  • 0

i have come to this strange issue.

i am getting values from array and trying to compare it but its not working.

Code-1

<?php
echo $data->item[0]['promocode'].'<br>';
echo $data->item[1]['promocode']; 
?>

Output-1

inhouse
inhouse 

Now lets try with if else condition if both values are same or not
Code-2

<?php
if(($data->item[0]['promocode']) == ($data->item[1]['promocode'])){
echo "both values are same";
} else {
echo "both values are NOT same";
}?>

Output-2

both values are NOT same 

Very strange

i dont get it what i am doing wrong.

lets try above exaple with specifying variables
Code-3

<?php
$data0=$data->item[0]['promocode'];
$data1=$data->item[1]['promocode'];
if($data0 == $data1){
echo "both values are same";
} else {
echo "both values are NOT same";
}?>

Output-3

both values are NOT same 

I am pulling my hairs now.


Now hard coding values in variables

Code-4

<?
$data0='inhouse';
$data1='inhouse';
if($data0 == $data1){
echo "both values are same";
} else {
echo "both values are NOT same";
}?>

Output-4

both values are same 

So my question is why is this happening ?

i have array of elements and i wanna check previous value with the current value if try then do something.

thanks for your time.

  • 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-17T23:27:07+00:00Added an answer on June 17, 2026 at 11:27 pm

    Assuming both entries are strings (as shown in your first code example) my guess would be that your entries have unequal leading and / or trailing whitespace. Try normalising them first, eg

    if (trim($data->item[0]['promocode']) == trim($data->item[1]['promocode']))
    

    To see what’s going on, try modifying your first example to

    <?php
        printf('<pre>"%s"%s"%s"</pre>',
            $data->item[0]['promocode'],
            PHP_EOL,
            $data->item[1]['promocode']);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never come across this issue but most recently I noticed that a
I have recently ran into this strange issue, I was trying to reference parent
I've come across a very strange issue that I have a workaround for, but
I have never seen this issue before, its very strange. Just wondering if anyone
Have been working on this question for a couple hours and have come close
We have come across a strange issue with ConcurrentHashMap , where two threads appears
I have come accross something very strange whilst trying to use deflate, I am
I have come across this problem in the past but never solved it. I
I have come across a very strange issue in python. (Using python 2.4.x) In
I've had this strange problem come up. I have a RowDataBound event handler for

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.