W
W
wusudewama2016-06-15 15:13:13
PHP
wusudewama, 2016-06-15 15:13:13

Why does explode in php give wrong result (different length of strings in resulting array)?

I am finishing the site on modx - there is a special construction that emulates if in the template.
I could not get it to work and I got into the code.
Inside there is approximately the following design (simplified for understanding)

$opers = explode(":is:", "8:is:8");
return $opers[0] == $opers[1];

The problem is that var_dump($oper) returns the following:
array(2) {
  [0]=>
  string(14) "8"
  [1]=>
  string(1) "8"
}

and accordingly, even though both elements of the array are equal to 8, but the comparison shows that this is not so.
Why does explode result in different lengths of strings (string(14) and string(1))? And how to do it right?
Thank you!
UPD.
The problem is probably the problem in the broken variable.
Tell me where to dig, is this the wrong encoding or what?
var_dump($is);
string(20) "8:ieq:8"

var_dump(explode(":ieq:",$is));
array(2) {
  [0]=>
  string(14) "8"
  [1]=>
  string(1) "8"
}

I didn't understand anything at all.
var_dump(bin2hex($is));
string(40) "5b2b6e6f6d696e6174696f6e2b5d3a6965713a38"
var_dump($is);
string(20) "8:ieq:8"

at the same time, the site string-functions.com/hex-string.aspx decrypts the string as
[+nomination+]:ieq:8
In the template, I just do
How can a binary representation of a variable show one thing and echo another?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2016-06-15
@entermix

$opers = explode(":is:", "8:is:8");
var_dump($opers);

Result:
10129358.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question