Re: Heredoc print to file? Use nowdoc. [message #172123 is a reply to message #172118] |
Mon, 31 January 2011 07:31 |
P E Schoen
Messages: 86 Registered: January 2011
Karma:
|
Member |
|
|
"Jerry Stuckle" wrote in message
news:ii5eo4$ov7$1(at)news(dot)eternal-september(dot)org...
> First of all, don't try to compare PHP an Perl. They are two
> different languages, and what you can do in one may or may
> not be done in the other (and it goes both ways).
Yes, I can see that, and it has been a learning experience doing the same
thing (which should be possible) in different ways (due to the language
differences). Now I'm having some difficulty with arrays, but I think I
found how to do what I want, although it seems ridiculous. I modified an
example in the manual to get this:
$qAll = "SELECT * FROM tEntries";
$result = $db->query($qAll);
$row = array("myArray");
$i = 0;
while($res = $result->fetcharray(SQLITE3_BOTH)){
if(!isset( $res['eid'] )) continue;
$row[$i][0] = $res[0];
$row[$i][1] = $res[1];
$row[$i]['et'] = $res['et'];
$i++;
}
print_r($row);
$maxrow = $i-1;
for($i=0; $i<$maxrow; $i++) {
fwrite( $fLog, "{$row[$i][0]} {$row[$i][1]} {$row[$i]['et']}\n");
fwrite( $fLog, "$row[$i][0] $row[$i][1] $row[$i]['et']\n");
}
I can't understand why you can assign an array element $row[$i][0] =
$res[0]; which is a simple scalar quantity (in this case an integer), but
when you use the same expression to write or print, it shows: Array[0], and
the curly braces are needed to extract to actual value. I only found this
deep in the user-supplied examples for arrays, and one would think this is
important enough to include in the main documentation.
http://www.php.net/manual/en/language.types.array.php
I didn't see anything in the array operators:
http://www.php.net/manual/en/language.operators.array.php
It’s not in operator precedence:
http://www.php.net/manual/en/language.operators.precedence.php
I did a search for php curly braces:
http://cowburn.info/2008/01/12/php-vars-curly-braces/
And from that I found this:
http://php.net/manual/en/language.types.string.php
So, now that I know this, I can proceed. It's probably still better than
Perl's various uses of $, %, #, and (), [], {}. Then you can throw in the @
operator and -> and => and all the other ASCII characters for a real
alphabet soup. OK, I'll stop complaining now. But I feel almost like the
victim of a joke, and I think I'll be fooled a few more times before I get
this project working.
:)
Paul
|
|
|