469,358 Members | 1,539 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

implode notice

I don't particularly need to do this but I've just found out that

print implode("<br>", $_SERVER);

Gives the warning :
Notice: Array to string conversion in c:\phpdev\www...

Doesn't do it with any other array and of course

foreach($_SERVER as $value){
print "$value<br>";
}

does exactly the same thing with no warning.

Curious, I am.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #1
5 3715
Geoff Berrow wrote:
I don't particularly need to do this but I've just found out that

print implode("<br>", $_SERVER);

Gives the warning :
Notice: Array to string conversion in c:\phpdev\www...


That's because $_SERVER is an associative array and implode() only works
with indexed arrays.

Therefore the following will work:

print implode("<br>", array_values($_SERVER));
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
That's because $_SERVER is an associative array and implode() only works
with indexed arrays.


This is *not* true, implode() doesn't care about the array type at
all, it just joins the array contents in its current sort order
without looking at the index values at all.

--
Hartmut Holzgraefe, Senior Support Engineer .
MySQL AB, www.mysql.com

Are you MySQL certified? www.mysql.com/certification
Jul 17 '05 #3
Geoff Berrow wrote:
I don't particularly need to do this but I've just found out that

print implode("<br>", $_SERVER);

Gives the warning :
Notice: Array to string conversion in c:\phpdev\www...

$_SERVER["argv"] is also an array, that's what is causing the
warning
Doesn't do it with any other array and of course
You just have to construct the right example and it does:

<?php
error_reporting(E_ALL);
$a = array(1,2, array(3,4));
implode("-",$a);
?>
foreach($_SERVER as $value){
print "$value<br>";
}

does exactly the same thing with no warning.


The "Array to String" conversion warning ist not thrown in all
situations where such a conversion happens

--
Hartmut Holzgraefe, Senior Support Engineer .
MySQL AB, www.mysql.com

Are you MySQL certified? www.mysql.com/certification
Jul 17 '05 #4
Hartmut Holzgraefe wrote:
This is *not* true, implode() doesn't care about the array type at
all, it just joins the array contents in its current sort order
without looking at the index values at all.


I stand corrected...
JW

Jul 17 '05 #5
Hartmut Holzgraefe wrote:
The "Array to String" conversion warning ist not thrown in all
situations where such a conversion happens


Appears to happen only when explicit casting is performed:

// Does not throw a notice:
print array(1,2);

// Does throw a notice:
print (string) array(1,2);
JW

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Andreas Paasch | last post: by
3 posts views Thread by Shawn Campbell | last post: by
6 posts views Thread by Rob | last post: by
11 posts views Thread by Jeff | last post: by
2 posts views Thread by DJ Craig | last post: by
4 posts views Thread by Stephen Kay | last post: by
18 posts views Thread by NoWhereMan | last post: by
6 posts views Thread by tokcy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.