explode() not working
Posted: Sat Nov 12, 2011 12:11 am
I have a function that takes in a string of the form "x|y|z...". In that function, I use explode to store it into an array.
This function is called from another file...
If I modify the function and hard-code the parameter value like this,
Or in the calling code,
Then it suddenly works. What's going on?
If I go back into the function and (when it's fed "1|2") I use a conditional like this...
It never hits the die() statement.
Code: Select all
function test($idList) {
$idArray = explode("|",$idList);
echo $idArray[0];
}Code: Select all
.
.
.
echo $values['userids']; // displays "1|2"
test($values['userids']); // displays "1|2"... why?
.
.
.Code: Select all
function test($idList) {
$idList = "1|2";
$idArray = explode("|",$idList);
echo $idArray[0];
}Code: Select all
.
.
.
echo $values['userids']; // displays "1|2"
test("1|2"); // displays "1"
.
.
.If I go back into the function and (when it's fed "1|2") I use a conditional like this...
Code: Select all
echo $idList; // displays "1|2"
if ($idList == "1|2") { // apparently false??
die("fail"); // never reached??
}