Page 1 of 1
convert str to int
Posted: Fri Jul 09, 2004 6:13 pm
by katanga
Code: Select all
<?
$highest=0;
foreach($s_data as $sub_rec) {
list($id, $naam, $bericht) = $sub_rec;
/* $convert=1;
$id=$id*$convert;
$id=(int)$id;*/
if($$highest<$id) {
$$highest=$id; } }
?>
I've used the function implode() to store everything in a var, after that I stored the data into a 2 dimensional array $s_data.
When I try to make my expression or when I try to do +1 with the value from my 2 dimensional array it wont work or the value becomes 0+1.
I think it's because $num is a string (gettype()) but normally this shouldn't give a problem @ all.
I've searched for 2 days now, a litle help would be welcome because this time google won't help
thx for reading,
grtz
Posted: Fri Jul 09, 2004 6:18 pm
by feyd
what does that code have to do with your problem? I don't get it.

Posted: Sat Jul 10, 2004 2:54 am
by markl999
The code looks like it's trying to get the highest value from an array. If so you can just use
http://php.net/max instead.
Posted: Sat Jul 10, 2004 4:28 am
by m3mn0n
Code: Select all
$int = (int) $string; // will define $string as an int
Posted: Sat Jul 10, 2004 6:54 am
by katanga
sami: thx but I already tried converting it to and integer that way, look @ my comment in code. Tried it with *1, +1 and (int).
max: thx, idd I tried to get the max of an array but it doesn't work, it's some kind of conflict with the string to integer converting.
result:
Array ( [0] => 15 [1] => 3 [2] => 2 [3] => 1 )
max: 3
grtz