Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
alvarito

Outputting Several Values From A Function

Recommended Posts

Hello

 

This is an application of page 302, my variant exercise

 

Been trying for the last two days to get the arguments sent by an object which calls a method, to an array which is in that method, and said array only gets the first of the arguments, as if it were a single scalar variable and not an array.

 

UPDATE

 

Someone solved the issue for me. The problem was that I was not passing the array into the object. I have to create the array, put the elements in there and then

 

This is the code that sends the arguments

 


require_once 'vehicle.php';
require_once 'Motorbike.php';


$v1 = 200;  // actually these are distances run at after 5, 10 and 15 seconds
$v2 = 300;
$v3 = 450;

$suzuki = new Motorbike();
$speeds = $suzuki->speed($v1, $v2, $v3);

echo "Speeds are: ";

foreach($speeds as $speed)
{
  echo $speed . "<br />";
}

 

UPDATED

 


$v = array(50, 20, 600);

$suzuki = new Motorbike();
$speeds = $suzuki->speed($v);

echo "Speeds are: ";

foreach($speeds as $speed)
{
  echo $speed . "<br />";
}

 

 

 


<?php


class Motorbike extends Vehicle {

protected $bikes_speed = array();
protected $speeds = array ();

public function speed($speeds){

  foreach($speeds as $speed)
  {
 	$this->bikes_speed[] = $speed/5;
  }

  return $this->bikes_speed;
   }

}



 

but this public function with argument $speeds, which is an array, is not getting the 3 values that I sent it from the code above, only the 200

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...