[nycphp-talk] convert str array to int ???
CHUN-YIU LAM
chun_lam at hotmail.com
Fri Mar 21 23:11:31 EST 2003
Sorry for the miss info. What I meant to say is that, there is only one
elementary type. This is always text (String if you will). Since I used to
do C/C++ with CGI. String is what I call it. Also the C/C++ does not have
String or Array Type. We just used char type. :-) Maybe it is just a
little too much detail (Maybe even useless in term of programming in PHP)
Matthew
----Original Message Follows----
From: "Steven Samuel" <steven at sohh.com>
Reply-To: talk at nyphp.org
To: NYPHP Talk <talk at nyphp.org>
Subject: RE: [nycphp-talk] convert str array to int ???
Date: Fri, 21 Mar 2003 10:32:08 -0500
Received: from parsec.nyphp.org ([66.250.131.26]) by
mc4-f4.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Fri, 21 Mar
2003 07:32:28 -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 h2LFW8JH029089for
<chun_lam at hotmail.com>; Fri, 21 Mar 2003 10:32:28 -0500 (EST)(envelope-from
null at nyphp.org)
X-Message-Info: JGTYoYF78jEHjJx36Oi8+Q1OJDRSDidP
Message-Id: <200303211532.h2LFW8JH029089 at parsec.nyphp.org>
X-Paralist-Archived: <http://nyphp.org/list/paralist_archive.php?L_mid=3559>
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: 21 Mar 2003 15:32:29.0173 (UTC)
FILETIME=[151BCA50:01C2EFBF]
"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/ ---
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
More information about the talk
mailing list