ppgpilot Posted October 17, 2006 Share Posted October 17, 2006 I have a problem and cannot find the answer...I am receiving an error - "Array to string conversion"on the page head I have the following which is throwing the error:[code=php:0]$_POST = array_map('stripslashes', $_POST);[/code]I am using a form multiple select box to select emails into an array:[code=php:0]<select multiple name="client_email[]" size="3" >EOT;$sql = ("select client_name, email from $tbl1");$result = mysql_query($sql);while ($row = mysql_fetch_array($result)){ $client_name = $row['client_name']; $email = $row['email']; echo "<option value=\"$email\">$client_name</option>";}[/code]then run the array through a php mail():[code=php:0]if(isset($_POST['client_email'])){if(is_array($_POST['client_email'])){ $client_email = $_POST['client_email']; foreach ($client_email as $email) { mail( $email, $subject, $client_message, $header ); }}elseif(!is_array($_POST['client_email'])){ $email = $_POST['client_email']; mail( $email, $subject, $client_message, $header );}}[/code]Then the error "Array to string conversion"If you have the answer and a fix, please let me knowThanksDavid Link to comment https://forums.phpfreaks.com/topic/24176-problem-with-error-array-to-string-conversion/ Share on other sites More sharing options...
akitchin Posted October 17, 2006 Share Posted October 17, 2006 i have a feeling that it's because array_map() only works one level deep. in other words, it strictly runs stripslashes() on $_POST['client_email'], not each of the $_POST['client_email'][]s themselves. therefore you're trying to convert the $_POST['client_email'] array into a string when passing it to stripslashes(), which expects a string.try replacing it with:[code]$_POST['client_email'] = array_map('stripslashes', $_POST['client_email']);[/code]you can also have a look in the comments in the php manual for array_map() for "deep_map." someone wrote a recursive function using array_map() so that it maps the given function to all levels of an array. i imagine this will be a better solution in the long run. Link to comment https://forums.phpfreaks.com/topic/24176-problem-with-error-array-to-string-conversion/#findComment-109880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.