473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Problem with foreach

All,
The code below was working fine until I upgraded to 4.3.10.
However, now, it displays:

c:\backups\sqlbackup\Array-020505-0951am.sql

instead of:

c:\backups\sqlbackup\a-020505-0951am.sql
or
c:\backups\sqlbackup\b-020505-0951am.sql
etc. etc. etc.

$dbnames = array ("a", "b", "c");
$savepath = "c:\\backups\\sqlbackup\\";
$date = date("mdy-hia");

foreach($dbnames as $dbname) {
$filename = $savepath . $dbname . "-" . $date . ".sql";
echo $filename;
}

Thanks.
Jul 17 '05 #1
6 1461
On Sat, 5 Feb 2005 10:02:50 -0900, "m|sf|t" <m|****@ampsycho.com> wrote:
The code below was working fine until I upgraded to 4.3.10.
However, now, it displays:

c:\backups\sqlbackup\Array-020505-0951am.sql

instead of:

c:\backups\sqlbackup\a-020505-0951am.sql
or
c:\backups\sqlbackup\b-020505-0951am.sql
etc. etc. etc.

$dbnames = array ("a", "b", "c");
$savepath = "c:\\backups\\sqlbackup\\";
$date = date("mdy-hia");

foreach($dbnames as $dbname) {
$filename = $savepath . $dbname . "-" . $date . ".sql";
echo $filename;
}


Well, it works as expected here. You could get Array if $dbnames was an array
containing a single array, or the single string "Array", or you'd mixed up
$dbname with $dbnames somewhere in the loop, but I don't see how the exact code
you posted could give that output.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:up********************************@4ax.com...
On Sat, 5 Feb 2005 10:02:50 -0900, "m|sf|t" <m|****@ampsycho.com> wrote:

Well, it works as expected here. You could get Array if $dbnames was an
array
containing a single array, or the single string "Array", or you'd mixed up
$dbname with $dbnames somewhere in the loop, but I don't see how the exact
code
you posted could give that output.


Thanks, that is the exact code that I am using here (Win2K, 4.3.10) and it
displays the info as I posted. I can't figure it out. Could it be a setting
in PHP.INI or something ?
Jul 17 '05 #3
On Sat, 5 Feb 2005 10:30:05 -0900, "m|sf|t" <m|****@ampsycho.com> wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:up********************************@4ax.com.. .
On Sat, 5 Feb 2005 10:02:50 -0900, "m|sf|t" <m|****@ampsycho.com> wrote:

Well, it works as expected here. You could get Array if $dbnames was an
array
containing a single array, or the single string "Array", or you'd mixed up
$dbname with $dbnames somewhere in the loop, but I don't see how the exact
code
you posted could give that output.


Thanks, that is the exact code that I am using here (Win2K, 4.3.10) and it
displays the info as I posted. I can't figure it out. Could it be a setting
in PHP.INI or something ?


Hm. Unless I'm missing something subtle, no, I still can't think of anything
that would produce that output from that code, whatever settings were changed.

FYI here's the exact code and result from my machine:

Z:\public_html>type test.php
<?php
$dbnames = array ("a", "b", "c");
$savepath = "c:\\backups\\sqlbackup\\";
$date = date("mdy-hia");

foreach($dbnames as $dbname) {
$filename = $savepath . $dbname . "-" . $date . ".sql";
echo $filename;
}
?>
Z:\public_html>d:\php-4.3.10-Win32\php.exe -q test.php
c:\backups\sqlbackup\a-020505-0740pm.sqlc:\backups\sqlbackup\b-020505-0740pm.sql
c:\backups\sqlbackup\c-020505-0740pm.sql

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #4
> Z:\public_html>type test.php
<?php
$dbnames = array ("a", "b", "c");
$savepath = "c:\\backups\\sqlbackup\\";
$date = date("mdy-hia");

foreach($dbnames as $dbname) {
$filename = $savepath . $dbname . "-" . $date . ".sql";
echo $filename;
}
?>
Z:\public_html>d:\php-4.3.10-Win32\php.exe -q test.php
c:\backups\sqlbackup\a-020505-0740pm.sqlc:\backups\sqlbackup\b-020505-0740pm.sql
c:\backups\sqlbackup\c-020505-0740pm.sql


Dang - I wasn't hoping for that. I pasted your code into a new file and
tried it, same ARRAY results. Argggh.

C:\PHP>php fromng.php
Content-type: text/html

c:\backups\sqlbackup\Array-020505-1048am.sqlc:\backups\sqlbackup\Array-020505-10
48am.sqlc:\backups\sqlbackup\Array-020505-1048am.sql
C:\PHP>

Thanks again.
Jul 17 '05 #5
On Sat, 5 Feb 2005, Andy Hassall wrote:
On Sat, 5 Feb 2005 10:02:50 -0900, "m|sf|t" <m|****@ampsycho.com> wrote:
The code below was working fine until I upgraded to 4.3.10.
However, now, it displays:

c:\backups\sqlbackup\Array-020505-0951am.sql

instead of:

c:\backups\sqlbackup\a-020505-0951am.sql


I suspect that you need to upgrade to the latest version of Zend
Optimizer (see the red text on this page:
http://www.php.net/downloads.php).

I saw exactly the same thing when I upgraded to PHP 4.3.10: inside foreach
loops which didn't use the keys as well as the values (eg foreach ($array
as $item) {...} rather than foreach ($array as $key => $value) {...}) PHP
would return an array each time, containing both the key and the value.
This went away when I reinstalled Zend Optimizer.

If this isn't your problem, then I'm at a loss :)

--
Matt
Jul 17 '05 #6
bingo bango - that did the trick =) thanks everyone for the help.

"Matt Raines" <matt@rai#remove#nes.me.uk> wrote in message
news:Pi******************************@hermes.athen s...
On Sat, 5 Feb 2005, Andy Hassall wrote:
On Sat, 5 Feb 2005 10:02:50 -0900, "m|sf|t" <m|****@ampsycho.com> wrote:
The code below was working fine until I upgraded to 4.3.10.
However, now, it displays:

c:\backups\sqlbackup\Array-020505-0951am.sql

instead of:

c:\backups\sqlbackup\a-020505-0951am.sql


I suspect that you need to upgrade to the latest version of Zend Optimizer
(see the red text on this page: http://www.php.net/downloads.php).

I saw exactly the same thing when I upgraded to PHP 4.3.10: inside foreach
loops which didn't use the keys as well as the values (eg foreach ($array
as $item) {...} rather than foreach ($array as $key => $value) {...}) PHP
would return an array each time, containing both the key and the value.
This went away when I reinstalled Zend Optimizer.

If this isn't your problem, then I'm at a loss :)

--
Matt

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: H. Adam | last post by:
hi ! i m trying to calculate an average array from an 2d data array. my problem is that my function does not generate an average array but just one value. but i do not understand why it does...
3
by: Paul Porcelli | last post by:
I have the following code(excerpt) which grabs some lines from a syslog file and adds any found in the range to an array. @lines=();@vvlines=(); $t = new Net::Telnet (Timeout => 30, Prompt =>...
0
by: Uma Abhyankar | last post by:
Hello, I had a program in .NET Beta1, where in I was programmatically traversing the Xml Schema using the given code snippet. However today with migration to Beta2, I am facing a compilation...
2
by: Uma Abhyankar | last post by:
Hello, I had a program in .NET Beta1, where in I was programmatically traversing the Xml Schema using the given code snippet. However today with migration to Beta2, I am facing a compilation...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
7
by: jimdscudder | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
2
by: Justin | last post by:
I don't use the foreach statement often so this problem has cought me off guard. Here is the code: foreach (int i in EventDates.Items) { DateList += EventDates.Items.ToString(); } I get an...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
4
by: Tony | last post by:
Hello! Below I have a complete working program.with some simple classes one of these is a generic class. The question is about this method GetCows() {...} which is a member in the generic...
9
tlhintoq
by: tlhintoq | last post by:
Situation: A Windows Form with a single User Control containing 4 custom controls. This lets me drop the User Control on its own form to make it a dialog, or make it part of a larger configuration...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.