Jump to content

Array_walk help


jadeg

Recommended Posts

I am trying to multiply every value in the array by 2. Below is my code. However i get the error Unsupported operand types in C 

<?php
session_start();

ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
$ftp_server="server";
$ftp_user_name="user";
$ftp_user_pass="pass";
	$conn_id = ftp_connect($ftp_server) or die ("Couldn't connect to $ftp_server");
	$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

	if($login_result) {
		echo '<h1> Last Second Reading for Bridgetford T1 </h1>';
		$handle=file('ftp://user:pass@server/public_html/test.csv');
		
			$data =array();
			$i=0;
			foreach ($handle as $row) {
				if($i==0){
					$i++;
					}
				else {		
				$data1= explode(",", $row);
				$count=count($data1);
					for($c=0; $c<$count; $c++) {
					if($c>0){
				$data[$i][$c]=$data1[$c]; // populate 2 by 2 array
						}						
					}
				$i++;
			
				}
			}	


function myarray (&$val)
{   $val=$val*2.0;
}
array_walk($data,'myarray'); 

		var_dump($data);
    }
            	   
	else {
		echo "There is a problem\n";
	}
	
ftp_close($conn_id); 

?>
Link to comment
Share on other sites

I just tried this on my local machine:

 

$data = array(4, 5, 6, 3, 4);
function myarray (&$val)
{   $val=$val*2.0;
}
array_walk($data,'myarray');
 
var_dump($data);

and it worked perfectly..

 

so, where exactly are you getting the error? And what is the full error?

 

Can you also do a dump of your $data array before you perform the array_walk, and post that here, so we can see what it is before hand.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.