RE: [PHP] Nested Arrays

2002-12-26 Thread Paul Reed
I didn't see this approach in any other reply. 

A multidimensional array is just an array of single dimensional
arrays... Basically $array[row#][col#]=$data;
$array[0][0]= "row0, col0"; 
$array[0][1]= "row0, col1";

This also works with associative arrays...

$cars[0]['make']="Ford";
$cars[0]['model']="Mustang";
$cars[1]['make']="Mazda";
$cars[1]['model']="RX7";

Although using an object/class would be better suited for the second
example

Hope this help .. 

Paul.

-Original Message-
From: Beauford.2002 [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, December 26, 2002 18:14
To: PHP General
Subject: [PHP] Nested Arrays

Hi,

Is there anyway to do a nested array, I have looked at the various array
functions and can't figure this out (if possible).

I want to be able to put each field of  a row into an array, and then
put
that entire row and into another array.

so when I display it, I would have:

row1 - col1  col2  col3 col4 col5
row2 - col1  col2  col3 col4 col5
row3 - col1  col2  col3 col4 col5
row4 - col1  col2  col3 col4 col5
row5 - col1  col2  col3 col4 col5

etc. (depending on how many rows there are).

TIA



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] object vs functions

2002-12-28 Thread Paul Reed
Objects are not simply a 'grouping' of functions, it's a fundamentally
different approach to programming where variable and functions are
grouped into objects. (OOP, or Object Oriented Programming)

Objects contain all the necessary variables to hold the information on
an item, and all the functions that work on that particular item.

A class is simply a 'blue-print' for an object. (each object is made
from that blueprint.)

Say for instance you were doing a used auto site, and this site had many
cars of different makes and models, and you wanted to assign a different
markup to each car.

Class c_Car
{
  var $make;
  var $model;
  var $color;
  var $cost;
  var $markup;

  function price()
  {
// '$this->cost' means the $cost variable in the current object.
$price=$this->cost+($this->cost*$this->markup);
return $price;
  }
}

// so I have 2 cars

$car1=new c_Car; 
$car1->cost=1;// what the car cost you.
$car1->markup=0.05;   // 5% markup from cost for this car.

$car2=new c_Car;
$car2->cost=7500; // what the car cost you.
$car2->markup=0.10;   // 10% markup from cost for this car.

echo $car1->price();  // output the price of car1, (10500).
echo $car2->price();  // output the price of car2, (8250).

As you can see, the function works internally to the object.

To learn more, you should really read up on OOP. Overall it's an easier
way to do most sites, but sometimes a simple collection of functions in
an include file may be more practical (usually for sites with very
little PHP).

In the last few months, I have shifted my own programming techniques to
use classes and I have found it tends to work better for almost every
situation. Personally, I wish I had found out about them sooner!

Hope this helps, (And I hope it makes sense, as I'm writing at 4:05am!)

Paul Reed.






-Original Message-
From: Mat Harris [mailto:[EMAIL PROTECTED]] 
Sent: Friday, December 27, 2002 21:18
To: [EMAIL PROTECTED]
Subject: [PHP] object vs functions

if i have a php script containing some functions, then all i have to do
is
include() the file and then call the functions.

if i had an object (taking the example from php.net):

do_foo();
?>
 
what is the point of having the object, when i could just call the
functions?

what are the uses of objects over functions/groups of functions?

sorry if this is an innane or frequently asked question.

-- 
Mat Harris  OpenGPG Public Key ID: C37D57D9
[EMAIL PROTECTED]www.genestate.com   



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php