convert str to int

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
katanga
Forum Newbie
Posts: 2
Joined: Fri Jul 09, 2004 6:13 pm

convert str to int

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what does that code have to do with your problem? I don't get it. :?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Code: Select all

$int = (int) $string; // will define $string as an int
katanga
Forum Newbie
Posts: 2
Joined: Fri Jul 09, 2004 6:13 pm

Post 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
Post Reply