NYCPHP Meetup

NYPHP.org

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

Steven Samuel steven at sohh.com
Fri Mar 21 10:26:28 EST 2003


"anything from a form is always a string"

That's not totally true...

Try this out:

<?php

function displayArray($array) {

	echo '<table width="500" border="1" cellspacing="1" cellpadding="3">';

	foreach ($array as $key => $value) {

		echo '<tr><td width="25%"><b>' . $key . '</b></td><td width="75%">' .
$value . '</td></tr>';

	}

	echo '</table>';

	return;

}

	if ($_POST['action'] == 'process') {

		displayArray($_POST);

	} else {

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>

<form method="post">

<input type="hidden" name="action" value="process">

<input type="text" name="name[first_name]" size="20">

<input type="submit">

</form>

</body>
</html>

<?php

	}

?>

The variable 'name' in the form is now an array.

-----Original Message-----
From: CHUN-YIU LAM [mailto:chun_lam at hotmail.com]
Sent: Friday, March 21, 2003 8:35 AM
To: NYPHP Talk
Subject: Re: [nycphp-talk] convert str array to int ???


First, anything from a form is always a string, because there isn't anything
that is past to your php script that says it is any other type.  Second, you
can use "array_merge.






----Original Message Follows----
From: Tracy <tech_learner at yahoo.com>
Reply-To: talk at nyphp.org
To: NYPHP Talk <talk at nyphp.org>
Subject: [nycphp-talk] convert str array to int ???
Date: Thu, 20 Mar 2003 01:07:08 -0500
Received: from parsec.nyphp.org ([66.250.131.26]) by
mc6-f37.law1.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Wed, 19 Mar
2003 22:07:55 -0800
Received: from nyphp.org (parsec.nyphp.org [66.250.131.26])by
parsec.nyphp.org (8.12.6/8.12.6) with ESMTP id h2K678JH090300for
<chun_lam at hotmail.com>; Thu, 20 Mar 2003 01:07:54 -0500 (EST)(envelope-from
null at nyphp.org)
X-Message-Info: JGTYoYF78jEHjJx36Oi8+Q1OJDRSDidP
Message-Id: <200303200607.h2K678JH090300 at parsec.nyphp.org>
X-Paralist-Archived: <http://nyphp.org/list/paralist_archive.php?L_mid=3532>
X-List-Software: Paralist 0.6
List-ID: <nyphptalk.nyphp.org>
List-Owner: <mailto:listmaster at nyphp.org>
List-Archive: <http://nyphp.org/list/paralist_archive.php?L_lid=2>
List-Subscribe: <http://nyphp.org/list/>
List-Unsubscribe: <http://nyphp.org/list/>
Organization: New York PHP
X-Mailer: Paramail 0.5
Return-Path: null at nyphp.org
X-OriginalArrivalTime: 20 Mar 2003 06:07:55.0906 (UTC)
FILETIME=[0CA7AE20:01C2EEA7]

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!







_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail



--- Unsubscribe at http://nyphp.org/list/ ---






More information about the talk mailing list