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

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

"anything from a form is always a string"

That's not totally true...

Try this out:


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>';



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


	} else {


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



<form method="post">

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

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

<input type="submit">






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

-----Original Message-----
From: CHUN-YIU LAM [mailto:chun_lam at]
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>
Reply-To: talk at
To: NYPHP Talk <talk at>
Subject: [nycphp-talk] convert str array to int ???
Date: Thu, 20 Mar 2003 01:07:08 -0500
Received: from ([]) by with Microsoft SMTPSVC(5.0.2195.5600); Wed, 19 Mar
2003 22:07:55 -0800
Received: from ( [])by (8.12.6/8.12.6) with ESMTP id h2K678JH090300for
<chun_lam at>; Thu, 20 Mar 2003 01:07:54 -0500 (EST)(envelope-from
null at
X-Message-Info: JGTYoYF78jEHjJx36Oi8+Q1OJDRSDidP
Message-Id: <200303200607.h2K678JH090300 at>
X-Paralist-Archived: <>
X-List-Software: Paralist 0.6
List-ID: <>
List-Owner: <mailto:listmaster at>
List-Archive: <>
List-Subscribe: <>
List-Unsubscribe: <>
Organization: New York PHP
X-Mailer: Paramail 0.5
Return-Path: null at
X-OriginalArrivalTime: 20 Mar 2003 06:07:55.0906 (UTC)

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 :

array(2) {
   array(2) {
     string(1) "0"
     string(1) "1"
   array(2) {
     string(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.


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*.

--- Unsubscribe at ---

More information about the talk mailing list