[PHP] Re: Problems with Arrays and print and echo
Michael Felt wrote: Slowly I am getting the output I want. Trying to use dynamic arrays, does creat the array I want, but getting the info is sometimes surprising. I notice a difference between arrays used locally in a function, and arrays used as a 'var' in a class function (all in PHP 4 atm). Code snippet: echo ROWS returned are: $max\n; $this-count = $max; while ($max--) { $row = mysql_fetch_row($result); $this-name[$max] = sprintf(%s, $row[0]); $Name[$max] = sprintf(%s, $row[0]); echo init \$this-Xame[$max] = $row[0]; echo $Name[$max] $this-name[$max]\n; $regionID[$max] = $row[1]; $constellationID[$max] = $row[2]; $this-ID[$max] = $row[3]; printf(%d:%d/%d/%s\n,$max,$regionID[$max],$constellationID[$max], $this-name[$max]); } Line wrap is messing things up a bit. Was trying sprintf to see if the was a buffer problem coming from mysql. Problem seems to be the same, regardless. Also, the names changes ($this-name[] versus $Name[]) are deliberate, for just in case Output (debuging): ROWS returned are: 7 init $this-Xame[6] = 8-TFDX 8-TFDX Array[6] 6:1003/2044/8-TFDX init $this-Xame[5] = B-E3KQ B-E3KQ Array[5] 5:1003/2044/B-E3KQ init $this-Xame[4] = BR-6XP BR-6XP Array[4] 4:1003/2044/BR-6XP init $this-Xame[3] = G5ED-Y G5ED-Y Array[3] 3:1003/2044/G5ED-Y init $this-Xame[2] = O-LR1H O-LR1H Array[2] 2:1003/2044/O-LR1H init $this-Xame[1] = UL-4ZW UL-4ZW Array[1] 1:1003/2044/UL-4ZW init $this-Xame[0] = Y5J-EU Y5J-EU Array[0] 0:1003/2044/Y5J-EU ++ Thanks for your ideas, help, etc.. Maybe it is somethign as simple as can't do that with echo, but when the arrays are all single element ( foo_array[0] is only element ) all statements work as expected. regards, Michael From - Fri Anyone? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Problems with Arrays and print and echo
Michael Felt wrote: Slowly I am getting the output I want. Trying to use dynamic arrays, does creat the array I want, but getting the info is sometimes surprising. I notice a difference between arrays used locally in a function, and arrays used as a 'var' in a class function (all in PHP 4 atm). Code snippet: echo ROWS returned are: $max\n; $this-count = $max; while ($max--) { $row = mysql_fetch_row($result); $this-name[$max] = sprintf(%s, $row[0]); $Name[$max] = sprintf(%s, $row[0]); echo init \$this-Xame[$max] = $row[0]; echo $Name[$max] $this-name[$max]\n; $regionID[$max] = $row[1]; $constellationID[$max] = $row[2]; $this-ID[$max] = $row[3]; printf(%d:%d/%d/%s\n,$max,$regionID[$max],$constellationID[$max], $this-name[$max]); } Line wrap is messing things up a bit. Was trying sprintf to see if the was a buffer problem coming from mysql. Problem seems to be the same, regardless. Also, the names changes ($this-name[] versus $Name[]) are deliberate, for just in case Output (debuging): ROWS returned are: 7 init $this-Xame[6] = 8-TFDX 8-TFDX Array[6] 6:1003/2044/8-TFDX init $this-Xame[5] = B-E3KQ B-E3KQ Array[5] 5:1003/2044/B-E3KQ init $this-Xame[4] = BR-6XP BR-6XP Array[4] 4:1003/2044/BR-6XP init $this-Xame[3] = G5ED-Y G5ED-Y Array[3] 3:1003/2044/G5ED-Y init $this-Xame[2] = O-LR1H O-LR1H Array[2] 2:1003/2044/O-LR1H init $this-Xame[1] = UL-4ZW UL-4ZW Array[1] 1:1003/2044/UL-4ZW init $this-Xame[0] = Y5J-EU Y5J-EU Array[0] 0:1003/2044/Y5J-EU ++ Thanks for your ideas, help, etc.. Maybe it is somethign as simple as can't do that with echo, but when the arrays are all single element ( foo_array[0] is only element ) all statements work as expected. regards, Michael From - Fri Some additional debug tests. Code: print_r($this-name); echo \nprint_r item 5\n; print_r($this-name[5]); echo \necho item 5 in quotes\n; echo \n$this-name['5']\n; echo \necho item 5 not in quotes\n; echo \n$Name[5]\n; echo \necho class item 5 not in quotes\n; echo \n$this-name[5]\n; exit; Output: Array ( [0] = Y5J-EU [6] = 8-TFDX [5] = B-E3KQ [4] = BR-6XP [3] = G5ED-Y [2] = O-LR1H [1] = UL-4ZW ) print_r item 5 B-E3KQ echo item 5 in quotes Array['5'] echo item 5 not in quotes B-E3KQ echo class item 5 not in quotes Array[5] == I am particilarily interested in the differences in these two echo statements with array variables in them. Why the difference in output? echo \necho item 5 not in quotes\n; echo \n$Name[5]\n; echo \necho class item 5 not in quotes\n; echo \n$this-name[5]\n; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php