Page 1 of 1

still problems with arrays

Posted: Sun Aug 29, 2004 8:09 am
by pelegk2
1i have this array :

Code: Select all

<?php
$lstOpenRounds ===
Array
(
    [0] => 006
    [1] => 97
    [2] => 1
    [3] => 012
    [4] => 162
    [5] => 1
    [6] => 012
    [7] => 163
    [8] => 1
    [9] => 019
    [10] => 160
    [11] => 2
    [12] => 019
    [13] => 158
    [14] => 1
)
?>
and i do :

Code: Select all

<?php
array_search ($row_orders_round['region_id'],$lstOpenRounds); 


?>
where $row_orders_round['region_id']=="002"
and i recive the 11 inde!!!!!
but in 11 index its "2" and not "002"
what is going on here?
thnaks i nadvane
peleg

Posted: Sun Aug 29, 2004 9:01 am
by markl999
That's because '002' == '2' but it doesn't === 2.
So use the third parameter to array_search which makes it also check the type.

Code: Select all

array_search ($row_orders_round['region_id'],$lstOpenRounds, TRUE);

but i built the array

Posted: Sun Aug 29, 2004 9:33 am
by pelegk2
as an array with string elements like this :
while($row=mysql_fetch_array($result)){
array_push($1stOpenRounds,"".$row['myVal1']);
array_push($1stOpenRounds,"".$row['myVal2']);
array_push($1stOpenRounds,"".$row['myVal3']);

}

Posted: Sun Aug 29, 2004 9:39 am
by markl999
Right, but you're in effect trying to match '2' with 2
So while '2' == 2 , '2' !== 2 i.e the values are the same but the types differ.
Did you try using the third argument to array_search() ?

Posted: Sun Aug 29, 2004 11:06 am
by pelegk2
well i am not at work a t the moment but i can tell u for sure that i tried to compare "002" with "002"
does the way i push values into the array dosent make them string?
is there a way to convert int into a string?

Posted: Sun Aug 29, 2004 11:45 am
by m3mn0n

Code: Select all

<?php
$foo = (int) $foo;
$bar = (string) $bar;
?>

Posted: Mon Aug 30, 2004 4:00 am
by Lord Sauron
Maybe this one works:

Code: Select all

<?php

array_search (".$row_orders_round['region_id'].",$lstOpenRounds); 

?>