NYCPHP Meetup

[nycphp-talk] convert str array to int ???

Jerry Kapron nyphp at NewAgeWeb.com
Thu Mar 20 05:28:35 EST 2003


Tracy,
Use intval() to get the integer value of a variable:

    $str = '22';
    // is_int($str) == false;

    $int = intval($str);
    // is_int($int) == true;

Jerry


--
42.7% of all statistics are made up on the spot.

-----Original Message-----
From: Tracy <tech_learner at yahoo.com>
To: NYPHP Talk <talk at nyphp.org>
Date: Thursday, March 20, 2003 1:08 AM
Subject: [nycphp-talk] convert str array to int ???


>
>Hi,
>i have a script which works with integers. i am taking the inputs from a
form and now it defaults to string. a var_dump gives :
>
>INPUTS :
>array(2) {
>  [0]=>
>  array(2) {
>    [0]=>
>    string(1) "0"
>    [1]=>
>    string(1) "1"
>  }
>  [1]=>
>  array(2) {
>    [0]=>
>    string(1) "1"
>    [1]=>
>    string(1) "1"
>  }
>}
>
>but i need the values to be ints....
>
>i tried :
>
>foreach ($pieces as $k => $v) {
> $$k = $v;
> echo $k ."=". $v ."<br>";
>//var_dump ($v);
> $cast = is_array ($v);
> if ($cast) {
>  foreach ($v as $key => $val) {
>   $$key = $val;
>   echo $key ."=". $val ."<br>";
>
>   $chk = is_int($val);
>   echo "variable type : $chk <br>";
>   if (!$chk) settype ($val,"integer");
>  }
> }
>}
>
>but still i am not able to type juggle. i have missed something but i am
unable to find out what. can someone plz identify what it is?
>is there a better way, i am not sure i am coding in the right way...
>
>also, i have two arrays, i want to merge them as :
>new[0] = array1[0], array2[0], array2[1]
>new[1] = array1[1], array2[1], array2[1]
>
>how to do this, i am again not getting the results like expected.
>
>Thz
>Tracy
>
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Coming together is a beginning...
>   keeping together is progress...
>      working together is success !!!
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
>
>
>--- Unsubscribe at http://nyphp.org/list/ ---
>
>




More information about the talk mailing list