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



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?

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"?

Thanks for helping me on these!

TTFN

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



Relevant Pages

  • 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)
  • Re: Probably very easy to do, but for some reason...
    ... For some reason, my brain has gone to mush on a couple of things. ... mysql_fetch_rows returns an array. ...
    (comp.lang.php)
  • Using an array of hair-thin electrodes implanted in his brain...
    ... Mind Over Matter ... ScienceNOW Daily News ... Using an array of hair-thin electrodes implanted in his brain, ...
    (sci.physics)
  • I watched a Brain op
    ... I nice young brain surgeon came with some fellow travellers and put a DVD ... spoon was used to drag some projection areas out. ... represent the input array and there is an array representing the desired ... faiths that do not match the faith of the doctor. ...
    (alt.religion.christian)
  • Re: replace 1 col from 2D array problem (further question?)
    ... I tried hard but, my brain is dead now, please help? ... I would suggest you rattle through the rows using autoindexing, search for a match, then add the desired element, building an new output array. ... It is not very efficient to rewrite the entire array at each iteration with a property node! ...
    (comp.lang.labview)