Skip to content
Advertisement

Getting values to compare from a Explode Array of Strings

I have this string that I’m Getting from a Mysql Result:

Result1:

JavaScript

Then, I have some ID from another mysql Result like this:

Result2:

JavaScript

Then I’m using an Explode in order to separate Result1:. Like I’m Getting this:

JavaScript

Now, I’m doing I’m using a foreach and then using another explode to separate the string by “/” delimiter.

JavaScript

The Result of this its something like this (for the firsts foreach iteration):

JavaScript

Ok, So I cannot Compare nota4[0] with $id from Result2:

Things that I’ve Tried:

  • Using if and verify every type, converts nota4[0] a $id to string

  • Try to use in_Array

  • Try to use strcmp($var1, $var2)

I’m Missing something but I really dont know what.

Also, when I tried I cant put nota4[0] into a html String like

JavaScript

Maybe its something silly but I tried everything without success.

Advertisement

Answer

You can make sure both are strings and trim and use a strict operator – even if it seems they are already that

JavaScript

Here’s another way to go about it. This will set up $result1 (or you can rename it) to become an associative array of key/value pairs, allowing you to loop through and compare a value like $result2 with a key id in the $result1 array. Example link included.

JavaScript

now to get $result2

JavaScript

Output of result1

JavaScript

https://www.tehplayground.com/1436vTBhUOYx9MNX

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement