472,125 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 3823
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

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.