Re: Probably very easy to do, but for some reason...



Hi,

On Jul 29, 1:58 pm, paulf.john...@xxxxxxxxx wrote:
Hi,

For some reason, my brain has gone to mush on a couple of things. Any
help would be appreciated.

I have an array and a field passed into a function (call it $v) which
is a string composed of comma sep values.

foo = array("one"=>1, "two", "three", "four", "five");
$ex = explode("," $v);
$newtext = "";
foreach ($ex as $e)
{
if ($e != "0")
$newtext .= " : " . $foo[$e];

}

The problem is that $e here is not being interpreted how I'd expect
(I'd assume it to be a number). Do I need to cast $e as an int or is
there something I'm missing?

You may want to do $e !== '0' to match the value and type exactly
without type conversions. You might occasionally get slightly
unintuitive results with regular comparison, e.g.: The expression
('-000' == '0') is true.

Try print_r on $e to check the unexpected result.

A related problem comes from an sql query.

mysql_fetch_rows returns an array (bar). I pass this to another
function. Next I try to iterate through.

The array appears to be a 2D array.

for ($m = 0; $m < count($bar); $m++)
{
for ($i = 0; $i < sizeof($bar[0]); $i++)
{
echo $bar['0']['3']; // works fine
echo $bar['0'][$i]; // doesn't work - same reason as above I'd
imagine
}

}

Probably a really simple answer, but one I can't figure out.

Final one - inserting an array into a table. I can't see anything
about this, but if I have an array which marries up exactly with the
fields in a table, can I just use "insert into tablename(*) values
($array) where ID=some_id"?

You can use MDB2_AUTOQUERY_INSERT to compose and execute a DML
statement from a value array.

Thanks for helping me on these!

TTFN

Paul
--
Sie können mich aufreizen und wirklich heiß machen!

.



Relevant Pages

  • Re: About Thread Completion Notify.
    ... This is the reason that i must keep track of the threads and they have to ... i remove it from the array. ... > (which you probably don't since you are servicing requests in separate ... you shouldn't have a need for waiting on events. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: please confirm something (jdbc)
    ... of its internal buffer so that will double the amount of memory that you need. ... That's the reason I wrote my own dynamic byte array ... Given all the memory re-allocation that goes on inside the ByteArrayOutputStream anyway, I'm not sure that one more allocation is all that much extra overhead. ... If I have two ways of coding something, and I know that one will definitely use less memory (or be quicker for whatever reason) then I will choose the one "better" one. ...
    (comp.lang.java.programmer)
  • Re: Help needed on Arrays
    ... What does the SQL Stored Procedure do? ... Is there a specific reason you want to create an extra ... be in an array or arraylist. ... The language is vb.net 2005. ...
    (microsoft.public.vsnet.general)
  • Re: what is the best datatype for..
    ... array that will be scanned searching for the index value, ... It also won't be flexible if the input data changes for any reason, since the implementation itself is so dependent on the input data. ... Calling the dictionary solution "inefficient" is just plain dumb; it might not be quite as fast as a straight array lookup, but it's not like it's a _slow_ design. ...
    (microsoft.public.dotnet.languages.csharp)
  • Probably very easy to do, but for some reason...
    ... my brain has gone to mush on a couple of things. ... I have an array and a field passed into a function which is a string composed of comma sep values. ... A related problem comes from an sql query. ...
    (comp.lang.php)