473,728 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($_SERVE R 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 3910
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($_SERVE R 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3207
by: Andreas Paasch | last post by:
I'm having trouble with the implode function and need some help here. I've been reading at php.net but that didn't solve my problem. I'm having the below code: $query = "SELECT top1, top2, top3, top4, top5, top6, top7, top8, top9, pricesmall, pricelarge FROM esperia WHERE productnumber = '$bestil'";
3
5488
by: Shawn Campbell | last post by:
Here's my scenario: I'm creating a build environment with one system acting as the main build dispatcher and other systems as the build hosts. On the main build system I have Apache, MySQL and PHP installed and I'm building a website that will allow people to view/start/etc. builds. I'm trying to get PHP to implode a log file that resides on one of the host builds systems. I have the host and and the share, so what I'm passing into...
6
5619
by: Rob | last post by:
hi, using PHP 4.3.3 and Apache (ADVX) 2.0.47 and i want to get the contents of my SETI stats site : $personal = implode("", @file("http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=$email&cmd=user_stats_new")); which gives me this :
11
2241
by: Jeff | last post by:
Hello. Quick background as I dont wish to hog anyones time. I am a customer of a PHP/SQL programmer. A website that I had the programmer build for me is working great, with one exception. I have limited programming experience, most of it Pascal/C++ and I haven't programmed for many years now even then it was mediocre programming of small this and thats.
2
1663
by: DJ Craig | last post by:
I have 2-dimensional array with numeric indices for both dimensions, called $results, which contains the search results from a database. The first dimension contains the records, and the second contains the fields. I want to convert it into an XHTML table to echo to the browser. For a 1-dimensional array, I would do this with implode(). Can I use implode() on a 2D array? If not, is there some other function I could use to do this, or...
4
1605
by: Stephen Kay | last post by:
Maybe I don't understand how to use this yet, but I was using (example): $html = implode('', file('http://www.mysite.com/transbar.html')); echo $html; This works. But if I try it on a .php file:
18
5921
by: NoWhereMan | last post by:
Maybe a stupid question. ------------------------- 1 ------------------------- $str = ''; for($i=0; $i<10; $i++) $str .= $i;
1
2363
by: scatfly | last post by:
I have a set of values that were put into a form and am now using this to put into a database. this is my error: "Warning: implode() : Bad arguments. in /home/xxxxxx/public_html/login.php on line 177 Couldn't execute insert query." $today = date("Y-m-d"); $fields_str = implode(",",$fields); $values_str = implode('","',$values); <=line 177 $fields_str .=",createdate";
6
2434
by: tokcy | last post by:
Hi, I am having a problem with implode() function in PHP. whenever i am running my code it display an error like. Warning: implode() : Bad arguments. in D:\xampp\htdocs\admin\addspecs.php on line 8 and my code is $as = $_POST;
0
8891
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9409
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9263
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9188
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9121
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2159
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.